Results 1 to 9 of 9
  1. #1
    terryvanduzee is offline Novice
    Windows XP Access 2003
    Join Date
    Oct 2009
    Posts
    17

    cbo value

    Hello

    Can anyone tell me what is wrong with my SQL statement Im trying to use on my form?
    Error:
    A RunSql Action requires an arguement consisting of a SQL Statement.

    Code:
    strSQL = "SELECT * " & _
    "FROM [tbl_CurrentInv] " & _
    "WHERE [tbl_CurrentInv].[Itemname]= " & _
    "'" & [Forms]![frm_Test]![Combo0].[Text] & "';"
    Any ideas?



    Thank you
    Terry

  2. #2
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows 10 Access 2013 32bit
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,922
    From VBA Help:
    Note To set or return a control's Text property, the control must have the focus, or an error occurs. To move the focus to a control, you can use the SetFocus method or GoToControl action.

  3. #3
    dcrake's Avatar
    dcrake is offline Competent Performer
    Windows XP Access 2003
    Join Date
    Aug 2009
    Posts
    435
    The RunSQL command will only work on action queries such as append, updates, deletes it is not designed for select queries.

    David

  4. #4
    CGM3 is offline Advanced Beginner
    Windows XP Access 2003
    Join Date
    Sep 2009
    Location
    Atlanta, GA
    Posts
    49
    Instead of the Text property, try using Value:
    Code:
    strSQL = "SELECT * " & "FROM [tbl_CurrentInv] " & "WHERE [tbl_CurrentInv].[Itemname]= " & "'" &
     [Forms]![frm_Test]![Combo0].[Value] & "';"
    And you can run a normal query in VBA, so create a query using that logic (and, yes, it can reference the combo control), put the name of the query in a string (here, cQueryName), and use this VBA command:
    Code:
    DoCmd.OpenQuery cQueryName, acViewNormal, acReadOnly
    The tricky part is getting people to close the query result that is displayed; I have this instruction in a label next to the list box I use to display available queries:
    To close the query, click on the LOWER x (e.g. Close Window) control at the upper right corner of the screen. Clicking on the upper x control will close the Access application.

  5. #5
    terryvanduzee is offline Novice
    Windows XP Access 2003
    Join Date
    Oct 2009
    Posts
    17
    Thank you

    I assigned the strSql to the recordsource. Works great

    Thank you
    Terry

  6. #6
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows XP Access 2002
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,922
    Great! Are you ready to use the Solved thread tool on this thread yet?

  7. #7
    terryvanduzee is offline Novice
    Windows XP Access 2003
    Join Date
    Oct 2009
    Posts
    17

    cbo value

    Thank you
    Yes I am ready to use the solved thread, but where do I find it?

    Thank you
    Terry

  8. #8
    Matrix's Avatar
    Matrix is offline Admin
    Windows XP Access 2003
    Join Date
    Jan 2005
    Posts
    531
    Thread Tools -> Mark this thread as solved.

    Detailed instruction

  9. #9
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows XP Access 2002
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,922
    I have a link in my signature.

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

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