Macros can do allot of things. If you need to pass a value to a query that you are calling from vb then you may want to look into creating a parameter to pass to the query instead?
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum.
That doesnt sound like it needs a function call to create a value then? It can all be done it the query except for the exporting. That could be done from a Macro and have the macro call the query first.
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum.
SELECT Duration_H_weekend.Segment, Duration_H_weekend.FullName, Sum(Duration_H_weekend.[In Handl]) AS [SumOfIn Handl], Sum(Duration_H_weekend.[Total Duration]) AS [SumOfTotal Duration], Duration_H_weekend.Weekend
FROM Duration_H_weekend INNER JOIN [ISA Table] ON Duration_H_weekend.[ACD EXT] = [ISA Table].[ACD EXT]
GROUP BY Duration_H_weekend.Segment, Duration_H_weekend.FullName, Duration_H_weekend.Weekend
HAVING (((Duration_H_weekend.Segment) Not Like "AYG" And (Duration_H_weekend.Segment) Not Like "TERM") AND ((Sum(Duration_H_weekend.[In Handl]))>0) AND ((Duration_H_weekend.Weekend)=getprevbusinessday(Date())));
Here is the function called in the last line of the query:
Public Function GetPrevBusinessDay(DayDate)
If Format(DayDate, "ddd") = "Sun" Then
GetPrevBusinessDay = DayDate - 2
ElseIf Format(DayDate, "ddd") = "Mon" Then
GetPrevBusinessDay = DayDate - 3
Else
GetPrevBusinessDay = DayDate - 1
End If
End Function
Let me offer up my class module to export queries from external databases, and using SQL instead of defined queries...
I have full instructions on another Forum... but I keep getting wrong for posting links to it in threads.. drop me a PM and I'll send you the link..
To get you started.. and this is only a text based file.. you need to copy all the code into a new class module.. call your module something and then include reference's to both MS Excel and DAO..
Then use code like..
VB Code:
Dim Exp As New clsExport 'or whatever you call it
With Exp
.DbName = "weekly dashboard.mdb"
.FileName = "Spreadsheet you are wanting exported to"
.SQL = "SELECT Duration_H_weekend.Segment, Duration_H_weekend.FullName, Sum(Duration_H_weekend.[In Handl]) AS [SumOfIn Handl], Sum(Duration_H_weekend.[Total Duration]) AS [SumOfTotal Duration], Duration_H_weekend.Weekend
FROM Duration_H_weekend INNER JOIN [ISA Table] ON Duration_H_weekend.[ACD EXT] = [ISA Table].[ACD EXT]
GROUP BY Duration_H_weekend.Segment, Duration_H_weekend.FullName, Duration_H_weekend.Weekend
HAVING (((Duration_H_weekend.Segment) Not Like 'AYG' And (Duration_H_weekend.Segment) Not Like 'TERM') AND ((Sum(Duration_H_weekend.[In Handl]))>0) AND ((Duration_H_weekend.Weekend)=getprevbusinessday(Date())));"
.Export
End With
I'll probably get wrong for suggesting pm'in the link to ya
Danny
Never Think Impossible
If you find my answer helpful then please add to my reputation
That seems like a lot of code to simply export a spreadsheet.
I failed to mention in my post with the code that the query called from the app calls the query with the function in it. I don't know if that makes a difference.
I tried using the macro, with no luck. It still opens the access vba editor.
It's a class module that prompts you for information and then supplies you with the output... Some of the advantages over TransferSpreadsheet are:
using existing spreadsheets and saving them under a different name after export
it will take a SELECT query's SQL rather than having to create the query then do the export...
Browse function on Spreadsheets and Databases
You can Transfer to Excel between databases..
I know the code's a lot, but you don't need to worry about that all you need to do is change a few properties and it does the hard part for you..
Danny
Never Think Impossible
If you find my answer helpful then please add to my reputation
It only allows a SELECT query, but it does also take the tablenames as well, in fact you can iterate through the tablename collection in the requested database and export either all of them or just a specific on..
You could make table from the cross tab and then export the resulting table...
Danny
Never Think Impossible
If you find my answer helpful then please add to my reputation
Do you know if there is a setting in Access that will cause the code editor to open. There will be a need in the future to use a function and I would like to know if this is possible.