How to pass a GUID from record to record in the same form

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • James Schoen
    New Member
    • Jan 2011
    • 2

    How to pass a GUID from record to record in the same form

    I have created a form that allows users to select a model number using a dropdown and click a button to open a sub-form. When it opens the sub-form, it passes the record id, in this case a GUID successfully. However, when the user enters a serial number on the sub-form and goes to the next record, it doesn't pass the GUID. I have been able to pass a simple text string (text29 - for testing) but just not the GUID.

    My reason for this is to allow users to enter multiple serial numbers assigned to the same model number without entering the model number in every time. I am a newbie to VBA and Access. So, any help is greatly appreciated.

    My code:
    Main Form:
    Private Sub Command24_Click ()
    RunCommand acCmdSaveRecord
    DoCmd.OpenForm "addMultipleNew Inventory"
    Forms!addMultip leNewInventory! partsLookupUUID .Value = Me!Combo9.Value
    Forms!addMultip leNewInventory! Text29.Value = Me!serialNumber .Value
    DoCmd.Close acForm, "Add New Inventory", acSaveYes
    End Sub

    Sub-Form:
    Private Sub Form_AfterUpdat e()
    Me!partsLookupU UID.Value = Me!partsLookupU UID.Value
    Me!Text29.Value = Me!Text29.Value
    End Sub
  • jimatqsi
    Moderator Top Contributor
    • Oct 2006
    • 1293

    #2
    James,
    Welcome. I think you'll find this site to be a huge help as you learn your way around Access and VBA.

    Here is a page I refer to constantly. It helps me get the syntax right for referring to objects on forms and subforms. http://www.mvps.org/access/forms/frm0031.htm

    Here are a few other basic. Change the names of your objects to be meaningful names. Command24 and Text29 do nothing to tell the purpose of those objects. And always put error checking into routines. Perhaps if you do that in this case you'll see where your problem lies. Your error checking will be something like this
    Code:
    On error goto Err_Command24_Click 'put this 1st in the routine
    'put the following code at the end of the routine and all other code goes between the above and the below code
    
       On Error GoTo 0
       Exit Function
    
    Err_Command24_Click:
    
        MsgBox "Error " & Err.Number & " (" & Err.Description & ") in procedure GetNewGuid of Class Module Command24_Click"
        Resume Next
    End Function

    I installed MZ-Tools from http://www.mztools.com/index.aspx. It is a fantastic free tool that puts the error checking in for you automatically with one click.

    Now, for your problem, it is not very clear what you are telling about the subform.

    It's not clear to me how you expect the information to flow from one form to the other. When your subform is updated there is no useful action taking place. The code
    Code:
    Me!partsLookupUUID.Value = Me!partsLookupUUID.Value
    Me!Text29.Value = Me!Text29.Value
    doesn't do anything

    I can't tell what "Me" is because I don't know what form's AfterUpdate event is being handled. It looks like it is part of form addMultipleNewI nventory. If that's so, then you probably want
    Code:
    Forms!mainformname!Combo9.Value = me!partsLookupUUID.Value 
    Forms!mainformname!serialNumber.Value = me!Text29.Value
    I'm not sure the subform's afterupdate event is the best place for that; maybe you could put it in the oncurrent event of the subform, so even if you don't update anything, if you're just browsing through the file you'll get the same effect. And also then in the afterupdate event of the the specific text boxes or other fields that might be edited.

    Hope that helps,
    Jim
    Last edited by jimatqsi; Jan 26 '11, 12:50 PM. Reason: add one detail to the end

    Comment

    • James Schoen
      New Member
      • Jan 2011
      • 2

      #3
      Thanks, I will look at it some more tomorrow. I will let you know how it goes. I really appreciate your speedy reply.

      Comment

      Working...