Full Version: What Is The Syntax Of Calling Function From Module Object
UtterAccess Forums > Microsoft® Access > Access Forms
I found function to export query into excel, the below statement is the 1st line of the function;
Public Sub sOutputQueryExcel(strQuery As String, strExcelTemplate As String, bolHeaders As Boolean)
Now what is the correct syntax to call "sOutputQueryExcel" from my button click event.
Oalways get argument is not optional error message.
Please can someone help me.
Many Thanks,
Hi rj,
There did you get that code? Didn't they explain how to use it?
From the looks of it, you would call it using something like:
sOutputQuery "QueryName", "ExcelTemplateName", True
I'm not sure if strQuery could also mean a SELECT statement, and I'm also not sure what they want for the Excel Template argument.
Hope that helps...
Hi theDBguy,
found it on code archive section.
I use the same syntax on Acc2007 but it did not work, is there any syntax different between Acc2003 and Acc2007?
Do you have any alternative way (the easy way) to export my query into excel? I need to add this functionality to convince the strong resistant of switching from Excel to Access for their database.
Many thanks,
You could just try the TransferSpreadsheet method. Have a look in the VBA help files for info on TransferSpreadsheet and see it that will suit your needs <
Do you have a link to the original code you found in the archive ? Are you leaving out one of the arguments for the sOutputQueryExcel sub routine (none of which are optional) ?
Hi Alan,
Can you please examine the below code (part only).
---start code--
Dim appExcel As Excel.Application
Dim exlWorkbooks As Excel.Workbooks
Dim exlRange As Excel.Range
Dim exlSelection As Object

Dim intRow As Integer
Dim lngColumnASCII As Long
Set db = CurrentDb

Set appExcel = GetObject(, "Excel.Application")
Set exlWorkbooks = appExcel.Workbooks

exlWorkbooks.Add Left$(CurrentDb.Name, Len(CurrentDb.Name) - Len(Dir(CurrentDb.Name))) _
& "Templates" & strExcelTemplate
---end code---
Oget the below error when I click my button.
"Error No: 1004; Description: Method 'Add' of object 'Workbooks' failed"
Am using Acc2007
Many thanks,
This is a "lo-fi" version of UA. To view the full version with more information, formatting and images, please click here.