View Single Post
  #2 (permalink)  
Old July 14th, 2009, 08:37 AM
mmcdonal mmcdonal is offline
Friend of Wrox
Points: 9,611, Level: 42
Points: 9,611, Level: 42 Points: 9,611, Level: 42 Points: 9,611, Level: 42
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Mar 2004
Location: Washington, DC, USA.
Posts: 3,069
Thanks: 0
Thanked 10 Times in 10 Posts
Default

You need to post more information than this.

An example of a SELECT query would be something like:

Code:
Dim sSQL As String
Dim rs As ADODB.Recordset
Dim cn As ADODB.Connection
 
sSQL = "SELECT * FROM MyTable"
 
Set cn = New ADODB.Connection
cn.open "DSN=MyDSNName" 'from your ODBC setup
 
Set rs = New ADODB.Recordset
rs.Open sSQL, cn, adOpenDynamic, adLockOptimistic
 
Do Until rs.EOF
'do something iterative with the data...?
 
 
rs.MoveNext
Loop
or

Code:
sSQL = "INSERT INTO MyTable(Username, LastName, FirstName) VALUES('mmcdonal', 'Mike', 'McDonald')"
...
 
rs.Open sSQL, cn, adOpenDynamic, adLockOptimistic 'this line does the insert
 
cn.Close

Then if you want to use variables...

Code:
Dim sUsername As String
 
sUsername = Me.Username 'referring to a form control
 
sSQL = "SELECT * FROM MyTable WHERE Username = '" & sUsername & "'"
 
...
rs,Open sSQL, cn, ...
Did any of that help?
__________________
mmcdonal

Look it up at: http://wrox.books24x7.com
Reply With Quote