Hello, I am reading my Access book with vba and the topic is ADO and I am "learning" the following
Dim cnnX As ADODB.Connection
Set cnnX = CurrentProject.Connection
Dim myRecordSet As New ADODB.Recordset
myRecordSet.ActiveConnection = cnnX
myRecordSet.Open SQLstatement
' cnnX = variable that defines the connection, you can leave it as 'cnnX(good '
'as any other name)
' myRecordSet is the name you want to give your record set(usaly left as 'myRecordset)
' SQLstatement is a valid that is NOT an ACTION query
But where do I put this. I tried under a button click event with a simple SELECT statement, but received an error indicating that this was not the right way to use this. Do I put the first part in a module an then call it with myRecordset.open. Am confused. Any help is appreciated. Tim
Dim cnnX As ADODB.Connection
Set cnnX = CurrentProject.Connection
Dim myRecordSet As New ADODB.Recordset
myRecordSet.ActiveConnection = cnnX
myRecordSet.Open SQLstatement
' cnnX = variable that defines the connection, you can leave it as 'cnnX(good '
'as any other name)
' myRecordSet is the name you want to give your record set(usaly left as 'myRecordset)
' SQLstatement is a valid that is NOT an ACTION query
But where do I put this. I tried under a button click event with a simple SELECT statement, but received an error indicating that this was not the right way to use this. Do I put the first part in a module an then call it with myRecordset.open. Am confused. Any help is appreciated. Tim