Question : Access VBA query naming

I have an Access 2003 database that I am creating query in and exporting to an Excel file.

I want one of the fields form the query (it is the same value for every record) to be part of the file name. This is what i was trying but not working - what do I need to get the field PaymentDate in the file name


stOutputName = stOutputName & strFileName
     stOutputName = stOutputName & .Fields("PaymentDate")
     

Answer : Access VBA query naming

Pdeters,

Use DLookup to grab a value from the query.

stOutputName = stOutputName & DLookup("PaymentDate", "QueryNameGoesHere")

But, if the target is actually a date, you may need to reformat it before it can be used in a file name (no slashes allowed in filenames!)

stOutputName = stOutputName & Format(DLookup("PaymentDate", "QueryNameGoesHere"), "mm-dd-yyyy")

Or use "yyyy-mm-dd" if you want the names to sort asciibetically.

HTH,

pT72
Random Solutions  
 
programming4us programming4us