By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
429,263 Members | 2,640 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 429,263 IT Pros & Developers. It's quick & easy.

How to open add new record form If record does not exist,?

P: 3
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
Jan 31 '11 #1
Share this Question
Share on Google+
1 Reply

Expert 5K+
P: 8,627
Expand|Select|Wrap|Line Numbers
  1. 'If UserID is NUMERIC
  2. intChk = DCount("*", "tblUser", "[UserID] = " & Forms!FrmCreateNewLaptopProfileForBookings![UserId])
  4. 'If UserID is TEXT
  5. intChk = DCount("*", "tblUser", "[UserID] = '" & Forms!FrmCreateNewLaptopProfileForBookings![UserId] & "'")
Feb 1 '11 #2

Post your reply

Sign in to post your reply or Sign up for a free account.