开发者

My AutoNumber Code Does Not Work

Can anyone help me here? I am trying to do a user defined autonumber when I click on a button. The code worked fine when the recordset is empty, it give me a 1 on my first record, however, after I click on the button again, it give me 1 again. Here's my code.

P开发者_开发技巧rivate Sub BtnNew_Click()
    Dim rsClone As Recordset
    Dim pVal As Integer

    Set rsClone = Me.RecordsetClone

    If Not (rsClone.BOF) Then
        DoCmd.GoToRecord , , acNewRec
        rsClone.MoveLast
        pVal = rsClone.AbsolutePosition + 2
        Me.CatgId.Value = pVal
        Me.CatgId.SetFocus
    Else
        rsClone.AddNew
        Me.CatgId.Value = 1
        Me.CatgId.SetFocus
    End If
End Sub

Thanks for the help.


I'm guessing that this is for a web page. If that's the case, every time your page handles any event, you're working with an entirely new instance of the page's type. That is, you're "Me" reference in that code points to a different object every time the function is called.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜