Results 1 to 3 of 3
  1. #1
    RobertIngles is offline Novice
    Windows XP Access 2007
    Join Date
    Jan 2011
    Posts
    5

    If record does not exist, open add new record form

    Hello all!



    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


  2. #2
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    Here's a good reference on the syntax:

    DLookup Usage Samples
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  3. #3
    jgelpi16 is offline Expert
    Windows XP Access 2010 32bit
    Join Date
    Mar 2010
    Location
    Charlotte, NC
    Posts
    544
    I would follow pbaldy's advice. Use a DLookup to check for the existence of the UserID. IF the UserID exists then you can trigger the CreatNewUserWhileBooking form.

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 1
    Last Post: 11-30-2010, 10:05 AM
  2. Open form which creates new record
    By mjhopler in forum Forms
    Replies: 7
    Last Post: 02-09-2010, 01:37 PM
  3. Open form to current record
    By rbpd5015 in forum Access
    Replies: 1
    Last Post: 08-28-2009, 01:53 AM
  4. Replies: 1
    Last Post: 05-16-2009, 08:47 AM
  5. Replies: 4
    Last Post: 03-24-2009, 09:07 PM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums