Results 1 to 2 of 2

Thread: problems with parametarized query in Access

  1. #1

    Thread Starter
    Member
    Join Date
    Apr 2005
    Posts
    47

    problems with parametarized query in Access



    i have this query in my Access database (saved as qryEditBook):

    UPDATE tblBook SET AuthorFirstName = [AuthorFirstName], BookName = [BookName], AuthorSecondName = [AuthorSecondName], BookEdition = [BookEdition], ISBN = [ISBN], Price = [Price], WebLink = [WebLink], DeweyCode = [DeweyCode]
    WHERE BookID=[BookID];


    in my VB app i do this (iam using DAO 3.6):

    [VB]
    MsgBox "edit"

    Set qd = dB.QueryDefs("qryEditBook") 'open query from db.mdb

    'fill up query's parameters
    qd.Parameters("BookName") = Trim(txtBookName.Text)
    qd.Parameters("AuthorFirstName") = Trim(txtAuthorFirstName.Text)
    qd.Parameters("AuthorSecondName") = Trim(txtAuthorSecondName.Text)
    qd.Parameters("BookEdition") = Trim(txtBookEdition.Text)
    qd.Parameters("ISBN") = Trim(txtISBN.Text)
    qd.Parameters("Price") = Trim(txtPrice.Text)
    qd.Parameters("WebLink") = Trim(txtWebLink.Text)
    qd.Parameters("DeweyCode") = Trim(txtDeweyCode.Text)
    qd.Parameters("BookID") = Trim(lblBookID.Caption)

    qd.Execute

    'clean up
    qd.Close
    Set qd = Nothing

    'refresh msflexgrid
    frmViewBooks.RefreshMSFlexGrid
    [/VB]

    for some reason it when i use the debuger it says that none of the items (ie the paramaters) are found in this collection.

    what is wrong with the above code?

  2. #2

    Thread Starter
    Member
    Join Date
    Apr 2005
    Posts
    47

    Re: problems with parametarized query in Access

    Using the:

    FieldName = [Prompt]

    syntax doesn't actually create an instance of a Parameter in the QueryDefs' Parameters collection. To do so, on the Query menu while in the designer for the query, select Parameters and then enter the Name and Data Type for the parameter.

    Then in the "Update To" part of the query designer, enter in the name of the parameters (as you've given them in the Parameters dialog box) within the square brackets.

Posting Permissions

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



Click Here to Expand Forum to Full Width