Results 1 to 3 of 3
  1. #1
    benthamq is offline Advanced Beginner
    Windows 7 32bit Access 2010 32bit
    Join Date
    Aug 2011
    Posts
    32

    Automatically Update Query Parameter w/ Code

    Hello,



    I am totally new to Access 2010 and inexperienced.
    I am trying to write code for an After Update event on a combo box (called Combo21 in my application) that will automatically supply a parameter to a parameter query based on the selection that the user makes in the combo box. The name of the query is qryUserPssPull and the parameter is enteruser.

    I have written this for the After Update event:

    Option Compare Database

    Private Sub Combo21_AfterUpdate()
    Dim userSelection As String
    userSelection = Combo21.Text
    DoCmd.SetParameter "enteruser", userSelection
    DoCmd.OpenQuery "qryUserPssPull"
    End Sub

    But when I try to run it the error message I get is this:
    Run-time Error '2766':
    The Object doesn't contain the Automation Object, "Thomas."

    (The combo box options are a list of employee names of which Thomas xxxxx is one. If I select a different employee name from the drop down list, I get the same message except with his/her name appearing in the error message.)

    I apologize for the fact that this code probably demonstrates I am not too good at this...I am very much still learning.
    I hugely appreciate any assistance offered. THANKS.

  2. #2
    June7's Avatar
    June7 is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,619
    Text is not the correct property, just drop it. The default property for data controls in VB/VBA is Value (VB.net uses Text), Value is the one you want.

    I never open tables or queries. I open forms and reports bound to the tables or queries. So have never used the SetParameter method. Not having luck making it work.

    Is this a multi-column combobox? Show the RowSource statement for the combobox. What is the structure of table the RowSource is based on? Is there an EmployeeID field? Really should search for the EmployeeID. Usually not good idea to search on names, what if you have several Thomas?
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  3. #3
    benthamq is offline Advanced Beginner
    Windows 7 32bit Access 2010 32bit
    Join Date
    Aug 2011
    Posts
    32
    Thank you for your help, the row source statement is this:

    SELECT tblUsers.UserID FROM tblUsers;

    The table has three fields, ID (primary key), Username, and Password.


    Even so, again I appreciate your help and I am just going to mark this thread solved - I guess there is a way to achieve this but I understand entirely the logic behind only opening reports and forms bound to the tables and queries as you state and I think that is clearly a better method to pursue.

    Thanks.

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

Similar Threads

  1. Replies: 2
    Last Post: 08-14-2011, 08:35 PM
  2. Replies: 1
    Last Post: 06-10-2010, 10:47 AM
  3. Replies: 3
    Last Post: 04-22-2010, 08:52 PM
  4. Help Automatically running and Update Query
    By JohnRandolphSTL in forum Queries
    Replies: 8
    Last Post: 04-13-2010, 02:08 PM
  5. Update Query with parameter query
    By mimikate in forum Queries
    Replies: 2
    Last Post: 03-16-2010, 09:10 PM

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