Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

If record does not exist, open add new record form

Status
Not open for further replies.

RobertIngles

Technical User
Jan 20, 2011
113
CA
I have a situation where my users need to enter details about new laptops into a table via FRMCreateNewLaptopID - the FRMCreateNewLaptopID includes a UserID field to identify the primary user.

They want to enter data into the UserID field in FRMCreateNewLaptopIDand click a confirmation button to see if the user does not exist then FRMCreateNewUserWhileBooking should open so they can enter the new user details which will be pushed to the FRMCreateNewLaptopID.

I have cobbled together the following code to open the user form in add mode however i get "Run time error 2428 you entered an invalid argumentin a domain agregate function.
What am I doing wrong?

Private Sub Command118_Click()
'Create var.
Dim intChk As Integer

'This line counts the number of rec instances in TBLUser.
intChk = DCount(UserID, TBLUser, FK = Forms!FrmCreateNewLaptopProfileForBookings!UserID)

'Does the rec exist? If not then open FRMCreateNewUserWhileBooking to add the new user details.
If intChk = 0 Then 'No?
DoCmd.OpenForm "CreateNewUserWhileBooking", , , , acFormAdd
Else 'Yes? Open the existing record in edit mode to check if updates are required
DoCmd.OpenForm FRMEditUser, , , "UserID = " & FrmCreateLaptopProfileForBookings!UserID

End If

End Sub
 
Probably this:
Code:
intChk = DCount("UserID", "TBLUser", "FK = Forms!FrmCreateNewLaptopProfileForBookings!UserID")

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Thank you so much PH - The add new user form opens fine now. Could I impose on someone to assist with the Else line? If the user already exists, I would like either a message to confirm existence or simply move the cursor to the next field which is [Barcode]. I promise y'all I am planning to do the Learning VBA in 24 Hours book this weekend but I don't have the 24 hours to get this working (and I suspect this might be beyond the scope of the course). Thanks so much for your help!!!

Private Sub Command118_Click()
'Create var.
Dim intChk As Integer

'This line counts the number of rec instances in TBLUser.
intChk = DCount("[UserID]", "TBLUser") = "Forms!FrmCreateNewLaptopProfileForBookings![UserID])"

'Does the rec exist? If not then open FRMCreateNewUserWhileBooking to add the new user details.
If intChk = 0 Then 'No?
DoCmd.OpenForm "FRMCreateNewUserWhileBooking", , , , acFormAdd
Else

DoCmd.Goto "Barcode"

End If


End Sub
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top