export query to excel and save file name with txt value (1 Viewer)

gippsy

Registered User.
Local time
Today, 15:10
Joined
Dec 15, 2012
Messages
39
In an MS Access Form I have 3 txtboxes to export querys to Excel
txtboxd. User picks a day from ms access calendar as dd/mm/yyyy
txtboxw. User enters week number as ww, yyyy
txtboxm. User enters month, year (mmm, year)

If user picks in textboxd 23_03_2017 I have a cmb with code to export query to Excel. However, exported query name is Me.txtcos_dy _queryname. But,
I need such file name as the date user picks, for example: 23_03_2017_queryname.:confused:
I have been googling and testing many ways with no success.:banghead:

Please, could you help me with that? Thx a lot!

Private Sub cmb_cos_dy_Click()
Dim filename1 As String
Dim filename2 As String

If DCount("*", "queryname") <> 0 Then
filename1 = "D:\Me.txtd " & "_" & "queryname" & ".xlsx"

Debug.Print filename2
DoCmd.OutputTo acOutputQuery, "queryname", acFormatXLSX, filename1, False

MsgBox "Query already exported to Excel"

Else
MsgBox "This day has no records"
DoCmd.Close acQuery, "queryname"
End If
End Sub
 

sneuberg

AWF VIP
Local time
Today, 13:10
Joined
Oct 17, 2014
Messages
3,506
Maybe:

Code:
filename1 = "D:" & Replace(Me.txtd,"/", "_")   & "_queryname.xlsx"

the replace function would replace the slashes with underscores.
 

gippsy

Registered User.
Local time
Today, 15:10
Joined
Dec 15, 2012
Messages
39
Hello.
The code Works as expected.:)
Thank you very much indeed.
 
Last edited:

Users who are viewing this thread

Top Bottom