export by date

awake2424

Registered User.
Local time
Today, 16:28
Joined
Oct 31, 2007
Messages
479
I am trying to export records to excel that are in a given month based on an input month. The user would select the month with the records desired and click the button to export them to excel. The attached zip file has an image of the database and the code behind the button is:

Code:
 Private Sub Command33_Click()
DoCmd.OpenReport "HLA_TAT", , , "Len(Exception & '') > 0 AND Receive_Date > #" & Forms!HLA_TAT.Date & "#"
End Sub

Code:
 can not access referenced form HLA_TAT [?CODE]

Thank you :).
 

Attachments

I don't see anything that is applicable unless I am missing something. Thanks :).
 
Forms!HLA_TAT.Date
ca only be accessed if HLA_TAT from is loaded.
Error message seems to note it is not loaded, or otherwise not in focus.

see if you can have it loaded or in focus, or have its value put in global memory when it is accessible.
 
The export button is within the HLA_TAT form. Thank you.
 
Then try using the Me keyword:

Me.Date.

referring through Forms or AllForms collections is necessary only when referring to a control from an other module (or object)
 
Also date is a reserved word you will need to wrap it in brackets [Date], or better yet change it to a non-reserved word

Also for your statement to work, your date field needs to be in US format, MM/DD/YYYY
 
Also date is a reserved word you will need to wrap it in brackets [Date], or better yet change it to a non-reserved word

Also for your statement to work, your date field needs to be in US format, MM/DD/YYYY
Don't use reserved words
 
I am getting Microsoft access cannot find the referenced the form HLA_TAT

I have modified the code to the below and am trying to have the user select the month from the dropdown and click the export button to have all records matching that month exported to excel.

Code:
Private Sub Command33_Click()
DoCmd.OpenReport "HLA_TAT", , , "Len(Exception & '') > 0 AND [Receive_Date] > #" & Forms!HLA_TAT.Month & "#"
End Sub

In the attached zip there is a screenshot of the db and the Receive Date and Month fields are the two in the code. Thank you :).
 

Attachments

a month is not the same as a date, if you are entering February you will ahve to "fix" that to a proper date in MM/DD/YYYY format

Docmd.openreport
 
I am having trouble modifying the below code to export the select records by Month:

VB
Code:
 Private Sub Command33_Click()
DoCmd.OpenReport "HLA TAT", , , "Len(Month & '') > 0 AND [Receive_Date] > #" & Forms![HLA TAT].Month & "#"
End Sub

As of right now when the user clicks on the export button, a prompt asking to input the Month and then another prompt for receive date results. Then when they are entered it prints the matching records. Is it possible to select the month on the form, then click on export and access matches the month to those records that where receive date is in the month? Thank you :).
 
Hi,
It seems to me that [Receive_Date] is assumed to be a field in the report. If it isn't, you should put there a name of a field from the report.
'Month' too, is from the function 'Len(Month & '')', and assumed to be a field in the report. (BTW, why concatenate an empty string to a string?)

All the best!
 

Users who are viewing this thread

Back
Top Bottom