Trash_Bandicoot
New member
- Local time
- Today, 15:12
- Joined
- Aug 24, 2018
- Messages
- 7
I've been fighting this code for some time now and its finally broken me... I'm trying to export the data from my database to specific cells in a specific workbook. I was able to do this just fine until I took it one step further and created a query with perimeters dictated by form to act as a search function. I've looked everywhere for a solution and I know that its because of these parameters that everything falls apart, but I'm just not good enough in VBA to find a workaround. Ive included the VBA code as well as the SQL from my Query. Any help is greatly appreciated!
Code:
DoCmd.OpenQuery "Shift Date Data Export", , acReadOnly
Dim rs As DAO.Recordset
Set objapp = CreateObject("Excel.Application")
objapp.Visible = True
Set wb = objapp.Workbooks.Open("G:\Crew Tracking\CT Reference\Other Reference Docs\Access Test Docs\Test 3\Back-End\Master Monthly Late Report Test 3.xlsm", True, False)
Set rs = CurrentDb.OpenRecordset("Shift Date Data Export")
For Each ws In wb.Worksheets
With ws
.Activate
.Cells(5, 2).CopyFromRecordset rs
End With
Next
rs.Close
Set rs = Nothing
Set objapp = Nothing
DoCmd.OpenForm "Late Report: Database Search"
Code:
SELECT [CREW AUTHORIZED LATE REPORT].[DEP DATE], [CREW AUTHORIZED LATE REPORT].STATION, [CREW AUTHORIZED LATE REPORT].[FLT NBR], [CREW AUTHORIZED LATE REPORT].[SKED DEP], [CREW AUTHORIZED LATE REPORT].[F/A REPORT], [CREW AUTHORIZED LATE REPORT].[PILOT REPORT], [CREW AUTHORIZED LATE REPORT].D0, [CREW AUTHORIZED LATE REPORT].A0, [CREW AUTHORIZED LATE REPORT].A14, [CREW AUTHORIZED LATE REPORT].NOTES, [CREW AUTHORIZED LATE REPORT].[Date Modified]
FROM [CREW AUTHORIZED LATE REPORT]
WHERE ((([CREW AUTHORIZED LATE REPORT].[Date Modified]) Between DateAdd("h",6,([Forms]![Shift Date Data Export]![txtBeginOrderDate])) And DateAdd("h",30,([Forms]![Shift Date Data Export]![txtBeginOrderDate]))));