Results 1 to 3 of 3
  1. #1
    Join Date
    Jan 2009

    Unanswered: Button on tab control to open and pass id to pop up form

    Hello, friends...

    I have a form, "frmClientDashboard" with a tab control on it. On one of the tab pages "Employment History", I have placed a command button, "cmdAddJob" which I want to a) open a pop-up modal form "frmAddEmploymentHistory" and b) pass the value of the current record's primary key "Client_ID" in frmClientDashboard to the pop up so that a fresh employment record can be created for that client and added to the tblEmployment table (the FK in tblEmployment is called "Employment_ClientID").

    On the same tab page as the button is a subform looking at tblEmployment, so, ideally, once the user has added a new job using the pop up, they would click Save & Close on the pop up and return to the tab control page on the main form to see the new job added to the subform window.

    Well, that's the plan anyway...BUT, I'm stuck at the open the pop-up part, or rather, the successful passing of the current record's id field to it. The pop up opens, and I can add a new job record, and that record saves to tblEmployment, but the Client ID does not get passed, and so it is not associated with the client.

    I'm posting my db. I'm working in Access 2007.

    Thanks in advance for any assistance you all can offer!

    Attached Files Attached Files

  2. #2
    Join Date
    Jan 2009
    Oh, also...this is the code I'm using, which is failing to work.

    Private Sub cmdAddJob_Click()
    'When "Add Job" button is clicked, open frmAddEmploymentHistory
    'to add new job for current Client

    Dim strFormName As String
    Dim strOpenArgs As String

    strFormName = "frmAddEmploymentHistory"
    strOpenArgs = "[Employment_ClientID] = " & Forms!frmClientDashboard.[Client_ID]

    DoCmd.OpenForm strFormName, , , , , , strOpenArgs

    End Sub

  3. #3
    Join Date
    Apr 2004
    Kingsland, Georgia
    You've got the right idea, just need to talk it out (pseudocode) to make things work right:
    click button on main form
    Button code should open new form and pass clientid as argument
    new form open should process that argument and create the new record.
    When the user clicks another button on the form (save and close), it should do what it's supposed to and then requery the subform on the main form.

    Looking at your db, you're almost there. Don't pass the whole "[Employment_ClientID] = " part, just the ID.

    You need to put in some code in the Form_Open event on the AddEmpHistory form so process the Client ID (which can be referenced by Me.Openargs)

    Good luck.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts