Hello!
There is an "external" ready query in Access with name " ZZ1 " with a single SQL line:
SELECT * FROM Tabl1 WHERE TTT=Q;
Q – external parameter.
If I run this query from Access, the system asks me the value Q, and I enter, for example, “A1”, and the query works correctly. Now I want to run the same query, but from the VBA EXCEL....
When I look at the Internet Examples I found this code, but it doesn’t work:
Public Con, rs As Object
Public Г±onStrRead As String
Function WritePeremToBD() As Boolean
PathToDB = ThisWorkbook.Path & "" & "DDD.mdb" ' ГЇГіГІГј ГЄ ГЃГ„
Г±onStrRead = "Provider=Microsoft.ACE.OLEDB.12.0;User ID=Admin;Data Source= " + PathToDB + _
";Mode=ReadWrite;Jet OLEDB:System database=;Jet OLEDB:Registry Path=;Jet OLEDB:Database Password="
End Function
Sub sp_ExecuteSQL()
Dim strConn As String
Dim CCon, oCmd, oPara As Object
'
Set CCon = CreateObject("ADODB.Connection")
Set oCmd = CreateObject("ADODB.Command")
Set oPara = CreateObject("ADODB.Parameter")
'
WritePeremToBD
CCon.Open Г±onStrRead
Set oCmd = CreateObject("adodb.command")
oCmd.ActiveConnection = CCon
oCmd.CommandText = "ZZZ1"
Set oPara = oCmd.CreateParameter("QQQ", adVarChar, adParamInput, 10)
oCmd.Parameters.Append oPara
oCmd.Parameters(0) = "A1"
oCmd.Execute
Conn.Close
Set Conn = Nothing
MsgBox "OK!"
End Sub
Please help!
Could you make for me an example
There is an "external" ready query in Access with name " ZZ1 " with a single SQL line:
SELECT * FROM Tabl1 WHERE TTT=Q;
Q – external parameter.
If I run this query from Access, the system asks me the value Q, and I enter, for example, “A1”, and the query works correctly. Now I want to run the same query, but from the VBA EXCEL....
When I look at the Internet Examples I found this code, but it doesn’t work:
Public Con, rs As Object
Public Г±onStrRead As String
Function WritePeremToBD() As Boolean
PathToDB = ThisWorkbook.Path & "" & "DDD.mdb" ' ГЇГіГІГј ГЄ ГЃГ„
Г±onStrRead = "Provider=Microsoft.ACE.OLEDB.12.0;User ID=Admin;Data Source= " + PathToDB + _
";Mode=ReadWrite;Jet OLEDB:System database=;Jet OLEDB:Registry Path=;Jet OLEDB:Database Password="
End Function
Sub sp_ExecuteSQL()
Dim strConn As String
Dim CCon, oCmd, oPara As Object
'
Set CCon = CreateObject("ADODB.Connection")
Set oCmd = CreateObject("ADODB.Command")
Set oPara = CreateObject("ADODB.Parameter")
'
WritePeremToBD
CCon.Open Г±onStrRead
Set oCmd = CreateObject("adodb.command")
oCmd.ActiveConnection = CCon
oCmd.CommandText = "ZZZ1"
Set oPara = oCmd.CreateParameter("QQQ", adVarChar, adParamInput, 10)
oCmd.Parameters.Append oPara
oCmd.Parameters(0) = "A1"
oCmd.Execute
Conn.Close
Set Conn = Nothing
MsgBox "OK!"
End Sub
Please help!
Could you make for me an example