I have a function that needs to get the report name of the report that its being used in and I can't figure out how to do this.
Here is the function. I have commented out the parts that I can't get to run, but might show what I want to do. I want to be able to use this function in multiple reports.
The function is called from a text box in Report XXXX.
I want the function to be able to fill in the XXXX for any report it runs in.
Thanks
Function MHList()
Dim oRS As Recordset
Dim sDistinctSQL As String
Dim sGeneralSQL As String
Dim sRecord
Dim sWONum() As String
Dim i As Integer
Dim strCSVals As String
Dim rptWO As String
'Dim rptName As String
'rptName = Screen.ActiveReport.Name
'MsgBox rptName
'rptWO = [Reports]![ & rptName & ]![txtWorkOrderNo]
rptWO = [Reports]![rptWObyProblem]![txtWorkOrderNo]
'Get the Distinct Work Order Numbers
sDistinctSQL = "SELECT DISTINCT WorkOrderNo FROM tblWONodes WHERE WorkOrderNo = '" & rptWO & "';"
Set oRS = CurrentDb.OpenRecordset(sDistinctSQL, dbOpenDynaset)
'Initialize i to 0
i = 0
If oRS.EOF <> True Then
Do Until oRS.EOF
'Re-dimension the array to make it bigger
ReDim Preserve sWONum(i) As String
'Store each number in the array
sWONum(i) = oRS.Fields(0).Value
i = i + 1
oRS.MoveNext
Loop
For i = LBound(sWONum) To UBound(sWONum)
sGeneralSQL = "SELECT tblWONodes.WorkOrderNo, tblWONodes.NodeID FROM tblWONodes WHERE WorkOrderNo = '" & rptWO & "' ORDER BY tblWONodes.WorkOrderNo;"
Set oRS = CurrentDb.OpenRecordset(sGeneralSQL, dbOpenDynaset)
Do Until oRS.EOF
sRecord = sRecord & oRS.Fields(1) & ","
oRS.MoveNext
Loop
If sRecord <> "" Then
sRecord = Left(sRecord, Len(sRecord) - 2) 'This will remove the last 2 characters from the string
MHList = sRecord
End If
Next
End If
oRS.Close
End Function
Here is the function. I have commented out the parts that I can't get to run, but might show what I want to do. I want to be able to use this function in multiple reports.
The function is called from a text box in Report XXXX.
I want the function to be able to fill in the XXXX for any report it runs in.
Thanks
Function MHList()
Dim oRS As Recordset
Dim sDistinctSQL As String
Dim sGeneralSQL As String
Dim sRecord
Dim sWONum() As String
Dim i As Integer
Dim strCSVals As String
Dim rptWO As String
'Dim rptName As String
'rptName = Screen.ActiveReport.Name
'MsgBox rptName
'rptWO = [Reports]![ & rptName & ]![txtWorkOrderNo]
rptWO = [Reports]![rptWObyProblem]![txtWorkOrderNo]
'Get the Distinct Work Order Numbers
sDistinctSQL = "SELECT DISTINCT WorkOrderNo FROM tblWONodes WHERE WorkOrderNo = '" & rptWO & "';"
Set oRS = CurrentDb.OpenRecordset(sDistinctSQL, dbOpenDynaset)
'Initialize i to 0
i = 0
If oRS.EOF <> True Then
Do Until oRS.EOF
'Re-dimension the array to make it bigger
ReDim Preserve sWONum(i) As String
'Store each number in the array
sWONum(i) = oRS.Fields(0).Value
i = i + 1
oRS.MoveNext
Loop
For i = LBound(sWONum) To UBound(sWONum)
sGeneralSQL = "SELECT tblWONodes.WorkOrderNo, tblWONodes.NodeID FROM tblWONodes WHERE WorkOrderNo = '" & rptWO & "' ORDER BY tblWONodes.WorkOrderNo;"
Set oRS = CurrentDb.OpenRecordset(sGeneralSQL, dbOpenDynaset)
Do Until oRS.EOF
sRecord = sRecord & oRS.Fields(1) & ","
oRS.MoveNext
Loop
If sRecord <> "" Then
sRecord = Left(sRecord, Len(sRecord) - 2) 'This will remove the last 2 characters from the string
MHList = sRecord
End If
Next
End If
oRS.Close
End Function