G
Guest
I have some code that takes a variable from a list box (an internal area
name) in a form, applys that variable to a query, runs the query and outputs
this to MS Excel. It also copies the Excel template
and renames it the same name as the variable.
This works fine although there are 120 different variables so I woudl like
to programmatically do this for each of the 120 variables. I know I need a
statement that does this once, focuses on the
list box, moves to the next record and then loops the code until it reaches
the last record.
Can anyone help with this code? I think I need a do loop function and a
move to next record comand but I cannot get either to work.
Any help or guidance would be very much appreciated. i have tried several
times to do this myself but I am getting to the point where I can't see the
wood for the trees!
Thank you for your time.
Martin
Here is my code so far:
_______________________________________________________
Private Sub ProduceReport_Click()
Dim SourceFile, DestinationFile
Dim AreaName As String
AreaName = Forms![Main Menu]![ADName]
DoCmd.TransferSpreadsheet acExport, 8, "qryCompetitors", "c:\Temp\AD
Pack", True, ""
DoCmd.OpenQuery "qryTimeOpenedCalc", acViewNormal
SourceFile = "c:\Temp\AD Pack.xls"
DestinationFile = "c:\temp\" & AreaName & ".xls"
FileCopy SourceFile, DestinationFile
End Sub
name) in a form, applys that variable to a query, runs the query and outputs
this to MS Excel. It also copies the Excel template
and renames it the same name as the variable.
This works fine although there are 120 different variables so I woudl like
to programmatically do this for each of the 120 variables. I know I need a
statement that does this once, focuses on the
list box, moves to the next record and then loops the code until it reaches
the last record.
Can anyone help with this code? I think I need a do loop function and a
move to next record comand but I cannot get either to work.
Any help or guidance would be very much appreciated. i have tried several
times to do this myself but I am getting to the point where I can't see the
wood for the trees!
Thank you for your time.
Martin
Here is my code so far:
_______________________________________________________
Private Sub ProduceReport_Click()
Dim SourceFile, DestinationFile
Dim AreaName As String
AreaName = Forms![Main Menu]![ADName]
DoCmd.TransferSpreadsheet acExport, 8, "qryCompetitors", "c:\Temp\AD
Pack", True, ""
DoCmd.OpenQuery "qryTimeOpenedCalc", acViewNormal
SourceFile = "c:\Temp\AD Pack.xls"
DestinationFile = "c:\temp\" & AreaName & ".xls"
FileCopy SourceFile, DestinationFile
End Sub