use combobox lookup value on one form to populate another form

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • erniemack
    New Member
    • Mar 2010
    • 10

    use combobox lookup value on one form to populate another form

    I have a form with a combobox using the following query:
    Code:
    SELECT   JobNumber,
             CustomerName,
             [PO],
             [Customer Motor #],
             assm_status
    FROM     tblJob
    WHERE    assm_status<>"Done"
    ORDER BY CustomerName;
    The bound column is column 1
    Code:
    Private Sub CustomerSearch_AfterUpdate()
    On Error GoTo Err_customersearch_Click
        Dim stDocName As String
        Dim stLinkCriteria As String
        Dim acct As Integer
        acct = Me.CustomerSearch.Value
        stDocName = "frmOESJOBmaint"
        DoCmd.OpenForm stDocName, , , "[jobnumber] = acct"
    Exit_customersearch_Click:
        Exit Sub
    Err_customersearch_Click:
        MsgBox Err.Description
        Resume Exit_customersearch_Click
    End Sub
    When you run this you are asked for the value for parameter "acct". If you input a jobnumber, the proper form/record is presented. I would like to eliminate having to input the parameter value again since the wanted record was selected in the combobox.

    Thanks
    Last edited by NeoPa; Mar 26 '10, 08:36 PM. Reason: Please use the [CODE] tags provided
  • NeoPa
    Recognized Expert Moderator MVP
    • Oct 2006
    • 32633

    #2
    Your code is not passing the value just stored in your variable acct. It is passing a reference into SQL of acct. As SQL has no idea what this may be (it has no link into your running VBA code) it requests a value from the operator.

    Try instead for line #8 :
    Code:
    DoCmd.OpenForm stDocName, , , "[jobnumber] = " & acct
    Welcome to Bytes!

    Comment

    • erniemack
      New Member
      • Mar 2010
      • 10

      #3
      Thanks that works like a champ!!!

      Comment

      • NeoPa
        Recognized Expert Moderator MVP
        • Oct 2006
        • 32633

        #4
        Always a pleasure. I hope you have a clearer understanding of why the previous version was having difficulties :)

        Comment

        Working...