Thank you, I will look into it. By specific cells --- very simple. I would like to export 3 pieces of data from the query to cells B7, B8 and B8. Hopefully, that is clear.
Exporting Access Query Data to Specific Cells in Excel: Guidance Needed
For a non-technical use, could someone please offer a detailed description, or refer me to one, that shows how to export data from an Access query or report to specific cells in Excel. Again, I am not proficient in Access.
Thank you
Microsoft 365 and Office | Access | For home | Windows
5 answers
Sort by: Most helpful
-
-
George Hepworth 22,080 Reputation points Volunteer Moderator2025-09-13T17:47:28.1133333+00:00 You'll find an example of exporting data from Access to Excel in a demo database on my website.
It shows one method. There are other approaches that might work as well.
Perhaps, though, it would be easier to provide more directed suggestions if you could provide a more detailed explanation of what you mean by "specific cells in Excel."
-
George Hepworth 22,080 Reputation points Volunteer Moderator2025-09-13T19:05:05.53+00:00 The code sample I have handy is probably too complex for your current needs, although does designate a range of cells for the output.
Public Sub ExportNPIntakeReports(dtStartDate As Date, dtEndDate As Date)Dim qdef As DAO.QueryDefDim xlapp As ObjectDim strtemplate As StringDim strreportPath As StringDim strSQL As StringDim strOutPutReport As StringDim strRange As StringDim LastRowIntakeDate As LongDim LastRowIntakeVal As LongDim LastRowNPDate As LongDim LastRowNPVal As LongDim LastRowAVKAPctVal As LongDim LastRowAVKAPctDate As LongDim LastRowSummary As LongDim LastRowPVDDate As LongDim LastRowPVDVal As LongDim i As LongDim db As DatabaseDim rst As DAO.RecordsetDim rstclinics As DAO.RecordsetOn Error GoTo ErrHandlerSet db = CurrentDbSelect Case fRolecheck(strUserID:=fOSUserName)Case 1strtemplate = "IntakeNPReports.xltm"Case Elsestrtemplate = ""MsgBox Prompt:="Report run by Executive Managers Only", Buttons:=vbOKOnly, Title:="Not Authorized"GoTo exitProcEnd SelectIf DCount("Clinic", "qryClinicNPINTakesBySelectedDateRange") = 0 ThenMsgBox Prompt:="There are no records in the selected Date Range", Buttons:=vbOKOnly, Title:="Select a Different Date Range"GoTo exitProcEnd IfstrreportPath = CurrentProject.PathSet xlapp = CreateObject("Excel.Application")With xlapp.Workbooks.Open strreportPath & "\" & strtemplate.Application.DisplayAlerts = False'' .Visible = TruestrSQL = "SELECT TreatmentTypeCode, A, B, C, D, HQ FROM qryClinicNPINTakesBySelectedDateRange_IntakesXtab"'2012-12-19 Export the NP section'check for records in the selected date rangeSet rst = db.OpenRecordset(strSQL, dbOpenDynaset, dbSeeChanges)If Not rst.EOF And Not rst.BOF Then.worksheets("Intake_NP").Select.range("IntakeSection").Select ' Send it to the detail section.activecell.Offset(0, 0).Value = "Intakes"For i = 1 To rst.Fields.Count - 1.activecell.Offset(0, i).Value = rst.Fields(i).NameNext i.range("IntakeSectionDetail").CopyFromRecordset rstEnd IfstrSQL = "SELECT TreatmentTypeCode, A, B, C, D, HQ FROM qryClinicNPINTakesBySelectedDateRange_NewPatientXtab"'2012-12-19 Export the NP section'check for records in the selected date rangeSet rst = db.OpenRecordset(strSQL, dbOpenDynaset, dbSeeChanges)If Not rst.EOF And Not rst.BOF Then.worksheets("Intake_NP").Select.range("NPSection").Select ' Send it to the detail section.activecell.Offset(0, 0).Value = "NP"For i = 1 To rst.Fields.Count - 1.activecell.Offset(0, i).Value = rst.Fields(i).NameNext i.range("NPSectionDetail").CopyFromRecordset rstEnd IfstrSQL = "From " & dtStartDate & " Through " & dtEndDate.worksheets("Intake_NP").Select.range("DateRange").Select ' Send it to the detail section.activecell.Offset(0, 0).Value = strSQL.range("A1:A1").SelectstrOutPutReport = strreportPath & "\NP_Intakes" & Format(Now(), "yyyy_mm_dd_HHmmss") & ".xlsx".ActiveWorkbook.SaveAs FileName:= _strOutPutReport, FileFormat:= _51, CreateBackup:=Falsexlapp.QuitShellExecute hwnd:=0, lpOperation:="Open", lpFile:=strOutPutReport, lpParameters:=0, lpDirectory:=0, nShowCmd:=1End WithCleanup:On Error Resume NextexitProc:On Error GoTo 0Exit SubErrHandler:MsgBox "Error " & Err.Number & " (" & Err.Description & ") in procedure ExportNPIntakeReports of VBA Document Form_frmDashboardNoCharts"Resume Cleanup:ResumeEnd SubThe relevant parts for your needs are where a range is designated and selected, followed by the
CopyFromRecordset method to export the query to that range.
-
William Bielfeldt 45 Reputation points
2025-09-13T20:38:44.8966667+00:00 You are correct. That is "way too complex" for probably my needs and, more important, to my understanding. I assume there is nothing where I "can paint by the numbers".
Thank you for your help.
-
William Bielfeldt 45 Reputation points
2025-09-14T14:34:29.4433333+00:00 Thanks for the response. I agree you would need more information to provide a correct solution. Since the post and since what I am trying to accomplish is simple, I found a simple cut and paste is the easiest approach and works well.
Again, thanks for your help.