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

vb 6 sql variable problem

Status
Not open for further replies.

Guest_imported

New member
Jan 1, 1970
0
Hi

I'm trying to pass a numeric variable to a adodc sql select statement.

e.g.

dim number
number = 5

// set up the database connection string

then in the record source adodc

Select * from cust where custID = number;

Any Ideas?

Cheers in advance

Mark
 
Hey mark, here's what you do:

"Select * From Cust Where CustID = " & number

Thats how we do it in code anyway.

Hope it helps,

Jack
 
Mark,

Check out where I assigned a SQL stmt to StrSQL.

Dim strSQL As String
dim intNumber as Integer

Dim cn As New ADODB.Connection
Dim rs As New ADODB.Recordset

cn.Provider = "Microsoft.Jet.OLEDB.4.0"
cn.ConnectionString = App.Path & "\MS_Access.mdb"
cn.Open

rs.CursorLocation = adUseClient
rs.CursorType = adOpenStatic

'A recordset containing the names of all the columns
strSQL = "SELECT * FROM tblCust " & _
"WHERE tblCust.CustID = " & intNumber
rs.Open strSQL, cn

'Do all your RecordSet stuff here...

'Don't forget to do some good housekeeping.
rs.Close
cn.Close

Hope it works for you...
 
Hi to all
Sheffield's code is good. But when you close a recordset, you should always use this code right after:

Set rs = Nothing
''Life is like a box of chocolate...''
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top