I am creating a function to loop through a list of names which will be used as criteria in the SQL. I have the framework for the loop working and want to first change the object name (BranchScorecardReport)to include the Recordset string strBranchName. That way I can loop through 160 branches giving them a unique and meaningful file name. I want the object name to be BranchScorecardReport.strBranchName.
Are there any suggestions on how to change the name of the Object Name as to include the value of the Recordset I have in the ? Thank you in advance.
--------------------------------------------------------------
Option Compare Database
Option Explicit
Function ScorecardReports()
Dim strOutputFormat As String
strOutputFormat = "PDF Format (*.pdf)"
Dim strObjectName As String
strObjectName = "BranchScorecardRprt"
'Reference to Current Database
Dim db As Database
Set db = CurrentDb()
'Identify table with names
Dim tbl As TableDef
Set tbl = db.TableDefs("Branch")
'Declare a string variable to hold the names
Dim strBranchName As String
strBranchName = ""
'Declare a counter for a loop
Dim i As Integer
i = 0
'Open a recordset against the table with names
Dim rst As Recordset
Set rst = tbl.OpenRecordset
With rst
If .RecordCount > 0 Then 'Verify records even exist first!
.MoveFirst 'Moves to the first position
Do While i <= .RecordCount And Not .EOF
strBranchName = rst!BranchName
i = i + 1
.MoveNext
Loop
Else
'Do Nothing
End If
End With
Debug.Print strBranchName
'Temporariliy Send Output from outside loop while I learn to change the Object Name to strObjectName.strBranchName
DoCmd.OutputTo acReport, strObjectName, strOutputFormat, "H:\Reports\BranchScorecardRprt", False, ""
End Function
Are there any suggestions on how to change the name of the Object Name as to include the value of the Recordset I have in the ? Thank you in advance.
--------------------------------------------------------------
Option Compare Database
Option Explicit
Function ScorecardReports()
Dim strOutputFormat As String
strOutputFormat = "PDF Format (*.pdf)"
Dim strObjectName As String
strObjectName = "BranchScorecardRprt"
'Reference to Current Database
Dim db As Database
Set db = CurrentDb()
'Identify table with names
Dim tbl As TableDef
Set tbl = db.TableDefs("Branch")
'Declare a string variable to hold the names
Dim strBranchName As String
strBranchName = ""
'Declare a counter for a loop
Dim i As Integer
i = 0
'Open a recordset against the table with names
Dim rst As Recordset
Set rst = tbl.OpenRecordset
With rst
If .RecordCount > 0 Then 'Verify records even exist first!
.MoveFirst 'Moves to the first position
Do While i <= .RecordCount And Not .EOF
strBranchName = rst!BranchName
i = i + 1
.MoveNext
Loop
Else
'Do Nothing
End If
End With
Debug.Print strBranchName
'Temporariliy Send Output from outside loop while I learn to change the Object Name to strObjectName.strBranchName
DoCmd.OutputTo acReport, strObjectName, strOutputFormat, "H:\Reports\BranchScorecardRprt", False, ""
End Function