R
Ronster
I am developing a small stand-alone Access application that uses many
queries and I am constantly making changes to the queries. I would
like to run the queries in VBA by simply calling them by name. This
seems easier than constantly changes the Select code in VBA. The
problem is I can't seem to get one query to run. From some other
posts it seems the best way to do this is to use ADO or ADODB neither
of which I am familiar with but I tried the following code and get the
error, "The database has been placed into a state by user Admin that
prevents it from being opened or locked."
I'm looking for a simple way to run queries from VBA. Am I on the
right track? Not sure what the error is telling me. I'm running
Access 2003 in Windows 2000.
Sub ExecuteQuery()
Dim adoComm As New ADODB.Command
Dim rs As New ADODB.Recordset
Dim strStringConnection As String
Dim strSPName As String
' I just copied this string from another post and just changed
' the Data Source to point to my DB. Not sure it will work with my
version
strStringConnection = "Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=C:\Import_Main.mdb;" _
& "Jet OLEDB:Engine Type=4"
strSPName = "DeleteDeductionRecords" 'NameOfYourQuery
adoComm.ActiveConnection = strStringConnection
adoComm.CommandType = adCmdStoredProc
adoComm.CommandText = strSPName
Set rs = adoComm.Execute
End Sub
Any help would be appreciated.
queries and I am constantly making changes to the queries. I would
like to run the queries in VBA by simply calling them by name. This
seems easier than constantly changes the Select code in VBA. The
problem is I can't seem to get one query to run. From some other
posts it seems the best way to do this is to use ADO or ADODB neither
of which I am familiar with but I tried the following code and get the
error, "The database has been placed into a state by user Admin that
prevents it from being opened or locked."
I'm looking for a simple way to run queries from VBA. Am I on the
right track? Not sure what the error is telling me. I'm running
Access 2003 in Windows 2000.
Sub ExecuteQuery()
Dim adoComm As New ADODB.Command
Dim rs As New ADODB.Recordset
Dim strStringConnection As String
Dim strSPName As String
' I just copied this string from another post and just changed
' the Data Source to point to my DB. Not sure it will work with my
version
strStringConnection = "Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=C:\Import_Main.mdb;" _
& "Jet OLEDB:Engine Type=4"
strSPName = "DeleteDeductionRecords" 'NameOfYourQuery
adoComm.ActiveConnection = strStringConnection
adoComm.CommandType = adCmdStoredProc
adoComm.CommandText = strSPName
Set rs = adoComm.Execute
End Sub
Any help would be appreciated.