Add 1 record by click on form button (1 Viewer)

xaysana

Registered User.
Local time
Today, 07:30
Joined
Aug 31, 2006
Messages
94
How can i add 1 new record after last record instead of (a defaultvalue adding new record, it does not populate any incremential number till adding some value) by clicking a new record button on main form please?

Here is my code:

Private Sub New_Click()
On Error Resume Next

DoCmd.GoToRecord , , acNewRec

Me.SerialNo.SetFocus

End Sub

Thank you for any help.
 

vbaInet

AWF VIP
Local time
Today, 01:30
Joined
Jan 22, 2010
Messages
26,374
So you want to add the ID only after any of the controls have been filled in?

In the On Dirty event of your Form:
Code:
If Me.NewRecord Then
    If Len(Me.[COLOR=Red]txtID [/COLOR]& vbNullString) <> 0 Then
        Me.[COLOR=Red]txtID[/COLOR] = DMax("[COLOR=Red]ID[/COLOR]", "[COLOR=Red]TableName[/COLOR]")
    End If
End If
Amend the bits in red. txtID is the name of the textbox that the ID field is bound to.
 

Users who are viewing this thread

Top Bottom