Results 1 to 9 of 9
  1. #1
    Merkava is offline Novice
    Windows XP Access 2002
    Join Date
    Nov 2009
    Posts
    20

    Send parameters to queries

    Hello All,



    On a form I would like to take a user's choice from a combo box and send it to a stored procedure.

    How can I do this?

    I thank you in advance for any assistance.

    Cheers,
    Aaron

  2. #2
    dcrake's Avatar
    dcrake is offline Competent Performer
    Windows XP Access 2003
    Join Date
    Aug 2009
    Posts
    435
    Are we actually talking about stored procedures or queries? what is you back end data media?

    David

  3. #3
    Merkava is offline Novice
    Windows XP Access 2002
    Join Date
    Nov 2009
    Posts
    20
    If my terminology is correct, I am using a stored procedure. I created a query, using the design view, and saved it. Attached is a screen shot of what I am refering to.



    Cheers,
    Aaron

  4. #4
    ChrisO is offline Novice
    Windows XP Access 2003
    Join Date
    Aug 2005
    Location
    Brisbane, Australia
    Posts
    27
    Generic reply (don’t expect it to work first-up on a copy/paste): -

    Code:
    Option Explicit
    Option Compare Text
    
    
    Private Sub cboAgentSelection_AfterUpdate()
        Dim strSQL As String
        
        strSQL = " SELECT *" & _
                 " FROM tblAgents" & _
                 " WHERE AgentPK = " & Me.cboAgentSelection.Column(0)
                 
        CurrentDb.QueryDefs("qryGetAllAgentInfoByAgentID").SQL = strSQL
    
    End Sub
    Hope that helps.

    Regards,
    Chris.

  5. #5
    Merkava is offline Novice
    Windows XP Access 2002
    Join Date
    Nov 2009
    Posts
    20
    Hi Chris,

    Thanks for your reply, but I am trying to avoid having the SQL in the code, this is why I have created queries in the design view. Some of the SQL statements are utterly monsterous.

    Cheers,
    Aaron

  6. #6
    ChrisO is offline Novice
    Windows XP Access 2003
    Join Date
    Aug 2005
    Location
    Brisbane, Australia
    Posts
    27
    Your original question was about sending to the Query and that has been done.

    The idea that 'utterly monstrous queries' really doesn’t have a lot to do with that question.

    The question was about the direction of information travel, namely, that the information travels to the Query and no request for that information was made or required by the Query.

    If it's a read back from the Query, meaning the Query asks for the parameters it requires before the Query is populated, then that is a different story which I prefer not to do.

    Using the Query builder does not preclude using the SQL view of the Query definition in VBA, it simply requires string manipulation.
    In fact, getting the SQL of the Query definition is a good place to start when transferring the Query to VBA.

    There are many reasons for writing Query definitions in VBA, and some reasons for not doing so, that’s up to the designer.

    However, I doubt if the size of the SQL string is one of the reasons not to.

  7. #7
    Merkava is offline Novice
    Windows XP Access 2002
    Join Date
    Nov 2009
    Posts
    20
    Hi Chris,

    I said "monsterous SQL statements". I would prefer to use a ready made query, to keep the code as uncluttered as possible.

    However if it is preferrable to add extremely long SQL statements in the code, as opposed to using "ready made" queries, I am always open to learning something new.

    So my original question stands, how can I pass parameters to a stored procedure (If I am using the correct terminology)

    Cheers,
    Aaron

  8. #8
    ChrisO is offline Novice
    Windows XP Access 2003
    Join Date
    Aug 2005
    Location
    Brisbane, Australia
    Posts
    27
    This is the only way I could late bind it and I would prefer to write the entire SQL string to the Query because it would be persistent: -

    Code:
    Option Explicit
    Option Compare Text
    
    
    Private Sub cboAgentSelection_AfterUpdate()
        Dim qryTemp As Object
        Dim rstTemp As Object
                 
        ' Ordinal position of Parameter.
        Const AgentID As Long = 0
                 
        Set qryTemp = CurrentDb.QueryDefs("qryGetAllAgentInfoByAgentID")
        
        qryTemp.Parameters(AgentID) = Me.cboAgentSelection.Column(0)
        
        Set rstTemp = qryTemp.OpenRecordset
        
        MsgBox rstTemp!SomeText
        
        rstTemp.Close
        Set rstTemp = Nothing
        
        qryTemp.Close
        Set qryTemp = Nothing
        
    End Sub

  9. #9
    Merkava is offline Novice
    Windows XP Access 2002
    Join Date
    Nov 2009
    Posts
    20
    Hello Chris,

    Thank you for your assistance. I will give this a try.

    Cheers,
    Aaron

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

Similar Threads

  1. Send email using SendObject instruction
    By stecco in forum Access
    Replies: 4
    Last Post: 09-09-2009, 01:55 AM
  2. Calculated and send to totals. Question
    By castellano in forum Programming
    Replies: 1
    Last Post: 06-12-2009, 12:40 PM
  3. Replies: 1
    Last Post: 05-01-2009, 07:33 AM
  4. Beginner trying to send email with attachment
    By ahm in forum Programming
    Replies: 2
    Last Post: 03-24-2009, 08:51 PM
  5. Net Send from a button on an Access form
    By Deb4995 in forum Forms
    Replies: 0
    Last Post: 10-19-2006, 10:19 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