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

RunSQL - Only for Action Queries?? 1

Status
Not open for further replies.

JackR

IS-IT--Management
Jun 7, 2001
10
0
0
US
If DoCmd.RunSQL can only be used for action queries,
how can you perform a simple SELECT (from a SQL table)
to return a table value to an Access function...?

Sorry, this seems too simple to me - I'm missing something here.... ?

Thanks,

Jack
 

To return a single value use DLookup function.

sVal = DLookup("[col1]","table1","[col2]=1")

To Open a table from code use the DoCmd OpenTable method.

DoCmd.OpenTable "table1", acViewPreview

To open an ADO recordset in VB code use the RecordSet Open method.

Dim cnn1 As ADODB.Connection
Dim rstEmployees As ADODB.Recordset
Dim strCnn As String
Dim varDate As Variant

' Open connection.
strCnn = "Provider=sqloledb;" & _
"Data Source=srv;Initial Catalog=Pubs;User Id=sa;Password=; "
Set cnn1 = New ADODB.Connection
cnn1.Open strCnn

' Open employee table.
Set rstEmployees = New ADODB.Recordset
rstEmployees.CursorType = adOpenKeyset
rstEmployees.LockType = adLockOptimistic
rstEmployees.Open "employee", cnn1, , , adCmdTable Terry Broadbent
Please review faq183-874.

"The greatest obstacle to discovery is not ignorance -- it is the illusion of knowledge." - Daniel J Boorstin
 
Hi Terry,

Thank you for your thoughtful response - am working with it now..

Thanks

Jon
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top