Results 1 to 4 of 4

Thread: [Resolved}how to get combo box value into sql statement?

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Nov 2002
    Posts
    150

    [Resolved}how to get combo box value into sql statement?

    hi,
    I have a sql statement that get's data based on a combo box value and I can't seem to cencatentate it properly. that's what I'm trying to do:

    rs.Open "SELECT * FROM tblEmployees Where Proj = sheet1.combo1.value ", CNN, adOpenDynamic, adLockOptimistic

    I want to populate one combo box based on the selection of the previous combo box.

    any help is appreciated.
    waely
    Last edited by waely; Jun 22nd, 2006 at 09:46 AM.

  2. #2
    PowerPoster techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,687

    Re: how to get combo box value into sql statement?

    That's because you've referenced the combo box from inside the SQL statement, which SQL will expect as a literal string.

    What you really need is this:
    s.Open "SELECT * FROM tblEmployees Where Proj = " & sheet1.combo1.value, CNN, adOpenDynamic, adLockOptimistic

    Unless Proj is a text field... in which case you need this:
    s.Open "SELECT * FROM tblEmployees Where Proj = '" & sheet1.combo1.value & "'", CNN, adOpenDynamic, adLockOptimistic

    -tg
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  3. #3

    Thread Starter
    Addicted Member
    Join Date
    Nov 2002
    Posts
    150

    Re: how to get combo box value into sql statement?

    thanks tg. Proj is a column in my database. either method I use I get this error message:
    [Microsoft][ODBC Microsoft access driver] Syntax error (missing operator) in query expression 'Proj = MSP22003'.

    what is the deal?

    thanks

  4. #4

    Thread Starter
    Addicted Member
    Join Date
    Nov 2002
    Posts
    150

    Re: [Resolved}how to get combo box value into sql statement?

    I changed the statement to bo
    rs.Open "SELECT * FROM tblemployees Where Proj" & " = '" & sheet1.combo1.value & "'", CNN, adOpenDynamic, adLockOptimistic

    and that fixed it.

    thanks

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