Results 1 to 7 of 7
  1. #1
    kevins is offline Novice
    Windows 7 32bit Access 2007
    Join Date
    Jan 2012
    Posts
    26

    VBA Code to Open Form

    I have created a button to do a saved import, and would like Access to then immediately open the form that I imported the information to. I can't figure out the right code though. Since it is the newest entry, therefore the highest ID number, I figured I could use a code that retrieve the max ID number but I can't quite figure it out. Any help would be greatly appreciated!

    Private Sub Command125_Click()
    DoCmd.RunSavedImportExport "New Candidate Import"


    DoCmd.OpenForm ("Candidate Details",,,[max(ID)],,,)
    End Sub

  2. #2
    June7's Avatar
    June7 is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,770
    Do not use parentheses. Need full criteria expression.

    DoCmd.OpenForm "Candidate Details", , , "[fieldname]=" & DMax("fieldname","tablename")

    "Candidate Details" is NOT used as subform?
    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
    kevins is offline Novice
    Windows 7 32bit Access 2007
    Join Date
    Jan 2012
    Posts
    26
    Thanks, June. I tried it and I'm still getting an error. Is there another piece of criteria I need to add? I've included a screenshot.

    Click image for larger version. 

Name:	vba.jpg 
Views:	10 
Size:	108.6 KB 
ID:	9624

  4. #4
    June7's Avatar
    June7 is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,770
    Candidates is table name? ID is autonumber field in Candidates table?

    You are missing the closing paren of the DMax().

    Remove that last comma because nothing follows.
    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
    kevins is offline Novice
    Windows 7 32bit Access 2007
    Join Date
    Jan 2012
    Posts
    26
    Yes, Candidates is the table name, and with each new candidate, a new ID is given which is just a higher number than the last. I've attached an image of the error I received. Thanks!Click image for larger version. 

Name:	vba.jpg 
Views:	11 
Size:	118.0 KB 
ID:	9627

  6. #6
    June7's Avatar
    June7 is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,770
    Look at my example in post2 again. There are no parenthesis enclosing the DoCmd arguments. Remove them from your code.
    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
    kevins is offline Novice
    Windows 7 32bit Access 2007
    Join Date
    Jan 2012
    Posts
    26
    Always one little detail

    Thanks June, it's working perfectly now!

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

Similar Threads

  1. Code info on Open form
    By FRSPA in forum Access
    Replies: 3
    Last Post: 07-02-2012, 04:37 PM
  2. Replies: 1
    Last Post: 05-03-2012, 02:25 PM
  3. open form code question
    By budchevy in forum Programming
    Replies: 7
    Last Post: 02-22-2012, 08:56 PM
  4. VB Code to open a form?
    By HeadGasket in forum Access
    Replies: 1
    Last Post: 01-24-2012, 08:26 PM
  5. Replies: 2
    Last Post: 02-26-2010, 08:14 AM

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