Adam McReynolds
Registered User.
- Local time
- Yesterday, 19:23
- Joined
- Aug 6, 2012
- Messages
- 129
I need to create an auto number on a text box in a form. I created it for the user to enter their own repair ID but now they want an auto number and it is the primary key. I would prefer it to build an increment of 1 on the last record in the table. I have my current code updating 2 tables simultaneously. Any help would be awesome. Help me get this guy off my back! Here is my current code:
Code:
Private Sub btn_new_repair_Click()
If IsNull(Me.txt_new_repair) Or Me.txt_new_repair = "" Then
MsgBox "Please Enter a Repair ID"
Me.txt_new_repair.SetFocus
Cancel = True
Exit Sub
End If
If DCount("RepairID", "TBL_REPAIRS", "RepairID = '" & Me.txt_new_repair & "'") > 0 Then
MsgBox "That Repair ID is already Created. Please Enter a new Repair ID or Search for the Record below in the search field"
Me.txt_new_repair.SetFocus
Cancel = True
Exit Sub
End If
DoCmd.SetWarnings False
DoCmd.RunSQL "INSERT INTO TBL_REPAIRS (RepairID) Values ('" & Me!txt_new_repair & "');"
DoCmd.RunSQL "INSERT INTO TBL_REPAIRS_BILLING (RepairID) Values ('" & Me!txt_new_repair & "');"
DoCmd.OpenForm "FRM_APU_CUST_INFO", , , "RepairID = '" & Me.txt_new_repair & "'"
DoCmd.Close acForm, "FRM_MENU"
DoCmd.SetWarnings True
End Sub