CharlesWhiteman
Registered User.
- Local time
- Today, 18:32
- Joined
- Feb 26, 2007
- Messages
- 421
Hi All, In my Db a user opens an unbound form, which on oppening retrieves the next autonumber value and remembers it in a hidden txt box. Once save is clicked then the values are saved to the database. However, i recognise that in a multi-user environment another user could also open the same form before the other user has clicked save and then there would be an error message so I'm using the following code to check this and am wondering if my method is the most efficient way of doing it?
'Check AutoNumber Has Not Already Been Taken
Dim StrAppointmentID As String
Dim DbID As String
Dim NewApptSQL As String
StrAppointmentID = Me.txtAppointmentID
StrDbID = Nz(DMax("[AppointmentID]", "TblAppointments"), 0) + 1
If StrAppointmentID = StrDbID Then
Me.txtAppointmentID = Nz(DMax("[AppointmentID]", "TblAppointments"), 0) + 1
Else
End If
' Save & Enter The Appointment Details
NewApptSQL = "INSERT INTO TblAppointments (AppointmentID, CustID, CustName, AppointmentType, AppointmentDate, AppointmentTime, AppointmentDuration, ApptWithName, ApptForName, BookedBy, BookedDate, MeetingSummary, AddedToOutlook)"
NewApptSQL = NewApptSQL & " VALUES(txtAppointmentID, txtCustID, txtCustName, txtAppointmentType, txtMeetingDate, txtMeetingTime, txtDuration, CbMeetingWith, txtRepresentative, txtMeetingBookedBy, txtDateBooked, txtMeetingBrief, cbAdded)"
DoCmd.RunSQL NewApptSQL
[Forms]![frmcust]![LbAppointments].Requery
'Check AutoNumber Has Not Already Been Taken
Dim StrAppointmentID As String
Dim DbID As String
Dim NewApptSQL As String
StrAppointmentID = Me.txtAppointmentID
StrDbID = Nz(DMax("[AppointmentID]", "TblAppointments"), 0) + 1
If StrAppointmentID = StrDbID Then
Me.txtAppointmentID = Nz(DMax("[AppointmentID]", "TblAppointments"), 0) + 1
Else
End If
' Save & Enter The Appointment Details
NewApptSQL = "INSERT INTO TblAppointments (AppointmentID, CustID, CustName, AppointmentType, AppointmentDate, AppointmentTime, AppointmentDuration, ApptWithName, ApptForName, BookedBy, BookedDate, MeetingSummary, AddedToOutlook)"
NewApptSQL = NewApptSQL & " VALUES(txtAppointmentID, txtCustID, txtCustName, txtAppointmentType, txtMeetingDate, txtMeetingTime, txtDuration, CbMeetingWith, txtRepresentative, txtMeetingBookedBy, txtDateBooked, txtMeetingBrief, cbAdded)"
DoCmd.RunSQL NewApptSQL
[Forms]![frmcust]![LbAppointments].Requery