Results 1 to 4 of 4
  1. #1
    Join Date
    Oct 2002
    Posts
    15

    Red face Unanswered: VBA(Query Results) -> subform..how?

    I would like to send Query results from inside a VBA procedure to a subform (subform name =child11), how can i do this? Here's my code for the procedure:

    Private Sub Command3_Click()
    Dim partsList As String
    partsList = "" & Forms![parts_form]![parts_list_box].Value
    Dim QDb As Database
    Dim Qry As QueryDef
    Set QDb = CurrentDb()
    Set Qry = QDb.CreateQueryDef(partsList & "_In_Stock_qry",
    "SELECT * " & _
    "FROM [" & partsList & "] " & _
    "WHERE ((([" & partsList & "].[PART]) IN
    (SELECT PART FROM SF1))) " & _
    "ORDER BY [" & partsList & "].[PART];")
    'Run the query
    DoCmd.OpenQuery partsList & "_In_Stock_qry", acViewNormal

    'Delete the query
    QDb.QueryDefs.Delete (partsList & "_In_Stock_qry")

    End Sub



    Thanks for your help....
    -The enemy of good is better...

  2. #2
    Join Date
    Oct 2002
    Location
    Sao Paulo - Brazil
    Posts
    16
    Hi supernewb,

    If i understood, try this:

    after created the query:

    child11.Form.RecordSource = partsList & "_In_Stock_qry"
    child11.requery
    Regards,

    Rogerio

  3. #3
    Join Date
    Oct 2002
    Location
    Sao Paulo - Brazil
    Posts
    16
    Hi supernewb,

    If i understood, try this:

    after created the query:

    child11.Form.RecordSource = partsList & "_In_Stock_qry"
    child11.requery
    Regards,

    Rogerio

  4. #4
    Join Date
    Oct 2002
    Posts
    15

    Getting closer...

    I think you put me on the right track but when I try this I get an error message:

    Error message '2467'
    The expression you entered refers to an object that is closed or doesn't exist.

    The code now looks like

    ...
    'Run the query
    DoCmd.OpenQuery partsList & "_In_Stock_qry"

    'Update the subform
    Child11.Form.RecordSource = partsList & "_In_Stock_qry"
    Child11.Requery

    'Delete the query
    QDb.QueryDefs.Delete (partsList & "_In_Stock_qry")


    The code the debugger highlights yellow with that error message is:

    Child11.Form.RecordSource = partsList & "_In_Stock_qry"

    Not sure whats up, if I knew had to change focus properly from a button to a subform, from inside a buttons click procedure, I may be able to just have the query make a table, and then I could access that temp table from the subform, well, thanks for the help :-)


    Originally posted by Rogerolim
    Hi supernewb,

    If i understood, try this:

    after created the query:

    child11.Form.RecordSource = partsList & "_In_Stock_qry"
    child11.requery
    -The enemy of good is better...

Posting Permissions

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