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 Rhinorhino on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Input Box Value to Sql String

Status
Not open for further replies.

Marke103

Technical User
Joined
May 18, 2001
Messages
4
Location
US
I have an Input Box that willl receive a numeric input. I want to assign the value to an inyeger variable and use it in a where clause in a sqlStr. Is this possible. What is the syntax. Below is the portion of cose I'm tryiong to do.


CoID = InputBox("Enter a Company ID Number", "Company ID")

strSQL = "Select * from tblpayments where IDNumber= &CoID order by PaymentDate"

Set RST1 = CurrentDb.OpenRecordset(strSQL, dbOpenDynaset)

I keep getting a syntax error. If i just put a numeric value like " where IDNumber = (1) " it works just fine, but I want to allow the user to enter a Value for IDNumber.

Any help would be greatly appreciated

 
You're very close. Remember that the Inputbox function returns a string. You should convert the user's entry to an integer or long integer before using the value in the SQL statement. Try this.

CoID = CLng(InputBox("Enter a Company ID Number", "Company )ID")
strSQL = "Select * from tblpayments where IDNumber = " & CoID & " Order by PaymentDate"
 
Thanks that worked just fine.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top