Hi all,
I have a query wich is filtered by a listbox on a form.
When i open the query it shows me the results i need.
If a open de query from VBA i get error 3061 and the query not shows data.
The main use of this is to put some data in an excel sheet so we can send to other people. If i not put the filter it works normally
I have a query wich is filtered by a listbox on a form.
When i open the query it shows me the results i need.
If a open de query from VBA i get error 3061 and the query not shows data.
The main use of this is to put some data in an excel sheet so we can send to other people. If i not put the filter it works normally
Code:
Private Sub Knop20_Click()
Dim objXL As Object
Dim xlWB As Object
Dim xlWS As Object
Dim rst As DAO.Recordset
Dim lngCount As Long
On Error GoTo Errorhandling
Set objXL = CreateObject("Excel.Application")
objXL.Visible = True
'Datapunten
Set xlWS = xlWB.Worksheets("Datapunten")
Set rst = CurrentDb.OpenRecordset("qry_Excel_Export")
aantal_rijen = DCount("*", "qry_Excel_Export") - 1
' Open it
With xlWS
For i = 0 To aantal_rijen
.Cells(1, 9).Select
.Rows("9:9").Select
Selection.Insert Shift:=xlDown
Next i
End With
lngCount = 9
Do Until rst.EOF
With xlWS
.Cells(lngCount, 1).Value = rst!Component
.Cells(lngCount, 2).Value = rst!OMSCH
.Cells(lngCount, 3).Value = rst!AI
.Cells(lngCount, 4).Value = rst!AO
.Cells(lngCount, 5).Value = rst!DI
.Cells(lngCount, 6).Value = rst!DO
.Cells(lngCount, 7).Value = rst!BUS
.Cells(lngCount, 8).Value = rst!Veldregelaar
.Cells(lngCount, 9).Value = rst!OPMERKING
.Cells(lngCount, 11).Value = rst!datapunten
.Cells(lngCount, 12).Value = rst!Indienstname
.Cells(lngCount, 13).Value = rst!Totaal
End With
lngCount = lngCount + 1
rst.MoveNext
Loop
rst.Close
Set rst = Nothing
Exit Sub
Errorhandling:
MsgBox Err.Number & Err.Description
End Sub