Hi all,
i am trying to create a report based on some dynamic SQL and i'm getting stuck. here's what i've got so far:
Public Function CreateDynamicRpt() As ADODB.Recordset
Dim cnn As ADODB.Connection
Dim rst As ADODB.Recordset
Dim sSQL As String
Set cnn = New ADODB.Connection
Set rst = New ADODB.Recordset
Set cnn = CurrentProject.Connection
If (Forms!frmFindingParam.ListBoxReqType = "All") Then
sSQL = "SELECT * FROM tblFindings;"
Else:
sSQL = "SELECT * FROM tblFindings WHERE tblFindings.ReqType = Forms!frmFindingParm.ListBoxReqType;"
End If
rst.Open sSQL, cnn
CreateDynamicRpt = rst
Set rst = Nothing
Set cnn = Nothing
End Function
sorry about the weird code formatting, but there are no line continuation marks in the code. all statement are on a single line. i saved this into a separate module named "mCreateDynamicRpt". I tried calling this function in the report's RecordSource property, but it isn't working. it says it doesn't recognize a macro named "mCreateDynamicRpt". to launch the report i created a command button. what am i doing wrong? is there a better way to do this? any help would be greatly appreciated.
Thanks a lot
i am trying to create a report based on some dynamic SQL and i'm getting stuck. here's what i've got so far:
Public Function CreateDynamicRpt() As ADODB.Recordset
Dim cnn As ADODB.Connection
Dim rst As ADODB.Recordset
Dim sSQL As String
Set cnn = New ADODB.Connection
Set rst = New ADODB.Recordset
Set cnn = CurrentProject.Connection
If (Forms!frmFindingParam.ListBoxReqType = "All") Then
sSQL = "SELECT * FROM tblFindings;"
Else:
sSQL = "SELECT * FROM tblFindings WHERE tblFindings.ReqType = Forms!frmFindingParm.ListBoxReqType;"
End If
rst.Open sSQL, cnn
CreateDynamicRpt = rst
Set rst = Nothing
Set cnn = Nothing
End Function
sorry about the weird code formatting, but there are no line continuation marks in the code. all statement are on a single line. i saved this into a separate module named "mCreateDynamicRpt". I tried calling this function in the report's RecordSource property, but it isn't working. it says it doesn't recognize a macro named "mCreateDynamicRpt". to launch the report i created a command button. what am i doing wrong? is there a better way to do this? any help would be greatly appreciated.
Thanks a lot