Results 1 to 4 of 4
  1. #1
    topp is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jun 2012
    Posts
    12

    Saving Autonumber field and using it to open new form

    Hello Everyone,



    I seem to be running into a slight problem that I think should be fairly easy, but given my lack of skills with Access I am having trouble figuring it out. I have a form that adds new records to a database with the PK set to an autonumber incremental field. After the users clicks on the create button I would like to open another form using the PK from the form that was just created. I have come very close I feel to solving this problem but for some reason just cant get everything to work out. When the user wants to save the information the have entered into the database I have a button with the following code:
    Code:
    Private Sub AddCertificate_Click()
    DoCmd.GoToRecord , , acNewRec
     End Sub
    In the AfterUpdate Event of the form I have this code grabbing the PK from the form that the information is entered on:
    Code:
    Private Sub Form_AfterUpdate()
    Dim TempCert As Integer
    TempCert = DLast("CERTNO", "dbo_RMA")
    MsgBox (TempCert)
    DoCmd.OpenForm "Cert of Conformance", acNormal, , "[CERTNO] = TempCert"
    End Sub
    Now I only placed to MsgBox in there to check and see if the DLast command was working and it is, because when the MsgBox pops up I see the PK from the last entered record. My problem comes when the OpenForm command executes because for some reason it doesn't see the value stored in the TempCert variable and prompts the user with a message box asking for the TempCert value. Any help is greatly appreciated!!

  2. #2
    orange's Avatar
    orange is offline Moderator
    Windows XP Access 2003
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,850
    for some reason it doesn't see the value stored in the TempCert variable
    Do some research on ReQuery and see if it applies. I think you may have to requery to get the latest value.

  3. #3
    topp is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jun 2012
    Posts
    12
    Orange,
    Ive tried both Requery on the form itself and Requery on the PK field and as well as the TempCert. None of them seemed to change the OpenForm command from asking for the TempCert number even though It recognizes the TempCert number in the msgbox.

  4. #4
    orange's Avatar
    orange is offline Moderator
    Windows XP Access 2003
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,850
    Can you post a dumbed down (remove personal/confidential data) version of your database in MDB format?

    Or create a small mdb from your database showing only relevant Form etc.

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

Similar Threads

  1. Creation of autonumber on open form
    By Pragmatic in forum Forms
    Replies: 1
    Last Post: 12-17-2011, 11:39 PM
  2. Replies: 1
    Last Post: 12-04-2011, 09:11 PM
  3. Replies: 7
    Last Post: 01-12-2011, 08:59 AM
  4. Autofill field based on autonumber field
    By frevilla in forum Forms
    Replies: 1
    Last Post: 09-11-2009, 02:50 AM
  5. Problems with autonumber field in a form
    By admaldo in forum Forms
    Replies: 0
    Last Post: 02-25-2008, 11:09 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