Results 1 to 8 of 8
  1. #1
    lynthel is offline Advanced Beginner
    Windows 7 64bit Access 2010 64bit
    Join Date
    Nov 2013
    Posts
    30

    Check for existing record then open form and populate

    I have a form that asks a user for a number (5 digits). I have an "on enter" macro that needs to check for an existing record. If an existing record is found, a different form will open and be populated with a table that is filtered with the 5 digit number. Or else it will open a separate form for user to input info to create a record for the 5 digit number.

    I am getting a 2001 error when macro runs. I have attached a screen shot of the macro.

    Any ideas would be greatly appreciated!



    Code:
     IF (DCount("[tiw_program_#]","[tbl_programs]","[tiw_program_#]=" & "[txtProgramQuery]")>0)
    Attached Thumbnails Attached Thumbnails Macro.JPG  

  2. #2
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,770
    Remove the quote marks that are enclosing the textbox name. The quote marks cause the name to be treated as literal text, not a variable input.

    Is [tiw_program_#] a number data type field?

    BTW, advise no spaces or special characters/punctuation (underscore is exception) in naming convention.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  3. #3
    lynthel is offline Advanced Beginner
    Windows 7 64bit Access 2010 64bit
    Join Date
    Nov 2013
    Posts
    30
    Thanks for the advice...will switch "#" to "no"...[tiw_program_#] is a 5 digit number that is defined as "number"...but now I am getting a "Type Mismatch" error

    Code:
    DCount("[tiw_program_#]","[tbl_programs]","[tiw_program_#]=" & [Forms]![frm_travelers_programs_blank]![txtProgramQuery])>0
    Last edited by lynthel; 03-31-2014 at 05:24 PM. Reason: adding code

  4. #4
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,770
    I don't use macros so am wildly guessing why this has issue.

    Is this code behind [frm_travelers_programs_blank]? Perhaps the form name reference is not required.

    Do you want the message box to say: "Switching to Program From"?
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  5. #5
    lynthel is offline Advanced Beginner
    Windows 7 64bit Access 2010 64bit
    Join Date
    Nov 2013
    Posts
    30
    "Switching to Program Form"....I just added message box code so I could see if the macro was working...how would you recommend I work around the macro? I am currently learning c#, have a little Java and HTML behind me, but really need to get the Access forms to work as desired...

  6. #6
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,770
    I use only VBA.

    Are you positive tlw_program_no is a number type field?
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  7. #7
    Subwind is offline Can Only Learn
    Windows XP Access 2010 32bit
    Join Date
    May 2012
    Location
    Portsmouth, UK
    Posts
    61
    What is the difference between the populated form layout and the blank form layout? Can you not just use the same form, if data exists, it is populated, if not, starts a new record....

    ~Matt

  8. #8
    lynthel is offline Advanced Beginner
    Windows 7 64bit Access 2010 64bit
    Join Date
    Nov 2013
    Posts
    30
    Code:
    If (DCount("[tiw_program_no]","[tbl_travelers_programs]","[tiw_program_no]=" & [Forms]![frm_travelers_programs_blank]![lstProgramQuery])>0)
    I finally got it to work...I had the wrong item in the second part of the If Statement...
    Now to brush up on how to pass a filter of the selected program to the form...

    Thanks for your help!

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

Similar Threads

  1. Replies: 11
    Last Post: 05-23-2012, 08:42 AM
  2. Replies: 4
    Last Post: 02-07-2012, 12:16 PM
  3. Replies: 5
    Last Post: 01-27-2012, 04:47 PM
  4. Replies: 0
    Last Post: 02-25-2011, 09:40 AM
  5. Replies: 2
    Last Post: 02-26-2010, 08:14 AM

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