Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

filling a data combo control from database table at run-time 1

Status
Not open for further replies.

kellyputty

Technical User
Jul 28, 2005
29
0
0
US
I am stumped. If I use a literal string in my SQL query below I get the correct result. If I use the value in a textbox, I get nothing. Not sure why.

Below: if instead of what I have in bold I insert 1001009, my dbcAccountID populates correctly, but not with txtCustomerID.text.

Any thoughts?

Code:
SQLCustomerAccount = "SELECT Customer.CustomerID, CustomerAccount.AccountID FROM Customer LEFT JOIN CustomerAccount ON Customer.CustomerID = CustomerAccount.CustomerID WHERE CustomerAccount.CustomerID =  [b]'" & txtCustomerID.Text & "'[/b]"

    With rsCustomerAccount
        .CursorLocation = adUseClient
        .CursorType = adOpenDynamic
        .LockType = adLockOptimistic
        .Open SQLCustomerAccount, conMB, , , adCmdText
    End With
    Set dbcAccountID.RowSource = rsCustomerAccount
 
If it's a numeric field you don't need the apostrophes, but you should Trim any spaces and do a specific conversion to Int:

....WHERE CustomerAccount.CustomerID = " & Cint(Trim(txtCustomerID.Text))


________________________________________________________________
If you want to get the best response to a question, please check out FAQ222-2244 first.
'If we're supposed to work in Hex, why have we only got A fingers?'
Drive a Steam Roller
 
If you want to dig around, you can do things like checking len(txtCustomerID.Text) and the value of txtCustomerID.Text = "1001009". The latter is likely to be false, if your text box isn't returning a record and the literal is.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top