Hi All,
in my Access database i have table and query for this table.
In Access everything is working very good.
But in VBA i can not run a Query - if I am using f8 (debugging button) there are working fine, but when I am starting whole macro the refresh query in access doesnt work.
Im am using ADODB.Connection.
My code is
Please help,
Jacek Antek
in my Access database i have table and query for this table.
In Access everything is working very good.
But in VBA i can not run a Query - if I am using f8 (debugging button) there are working fine, but when I am starting whole macro the refresh query in access doesnt work.
Im am using ADODB.Connection.
My code is
Code:
Sub SQL_Baza()
Dim Connectstr As String
Dim HurtowniaADO As New ADODB.Connection
Dim ZdanieSQL As String
Dim Login As String
Dim FileName As String
Dim Moja As New MyForm
Dim Lokalizacja_Pliku As String
Dim Lokalizacja_Folderu As String
Dim TimeEntry As String
Dim TicketNumber As String
Dim Wiersz As String
Dim rs As ADODB.Recordset
Dim NumerSpółki, User, CzasWpisu As String
Dim rsQuery As ADODB.Recordset
Dim NumerZgłoszenia As String
// path of database
Lokalizacja_Pliku = "C:\Users\ljar01\Desktop\Makro\Pełnomocnictwa\Baza_Pełnomocnictwa.mdb"
Lokalizacja_Folderu = "C:\Users\ljar01\Desktop\Makro\Pełnomocnictwa\"
//name of Excel
FileName = "'" & ThisWorkbook.FullName & "'[Excel 8.0;]"
// login and ticker number which are added to table in Access.
Login = Moja.Login()
Wiersz = Wpisy.Range("A1").CurrentRegion.Rows.Count
TicketNumber = Wpisy.Cells(Wiersz, 1)
'TimeEntry = Wpisy.Cells(Wiersz, 2)
'''Login = "ljar01"
'''TicketNumber = "5000020"
'''TimeEntry = "29-08-2016 14:33:33"
Set Moja = Nothing
// connection string
Connectstr = "DSN=MS Access Database;DBQ=" & Lokalizacja_Pliku & ";DefaultDir=" & Lokalizacja_Folderu & ";DriverId=25;FIL=MS Access;MaxBufferSize=2048;PageTimeout=5;"
On Error Resume Next
HurtowniaADO.Open Connectstr
//open table
Set rs = New ADODB.Recordset
rs.Open "tb_wpisy", Connectstr, adOpenKeyset, adLockOptimistic, adCmdTable
/add new row to the table - this is working good!
With rs
.AddNew
![NumerSpółki] = TicketNumber
![User] = Login
.Update
.Save
End With
/refresh query - [B]this is not working at all[/B]
docmd.openquery "qry_tb_wpisy", acViewNormal, acUpdate
// [B]this method i also have tried - with no success[/B]
Set rsQuery = New ADODB.Recordset
rsQuery.Open "qry_tb_wpisy", Connectstr, adOpenKeyset, adLockOptimistic, adCmdTable
With rsQuery
.Update
.Save
End With
Please help,
Jacek Antek