Dear Friends
i have created a function that will populate the values in a report from a query
if i set month value in query as "JULY" then the report shows all the values and below function runs perfectly. as shown below
the report shows all the values...without error
Then added a form with combo to select the month from the list as shown below
and Open the report, it gives error on the same function
Below is the code, kindly help me why this is happening and how could i get solve that issue
Function MonthTranscation(BankName As String, FieldNo As Integer) As Long
Dim Name_Field_DB, Name_Field As String
Dim Amount_Field As String
Dim TotalNo_Field, Number_Field As Integer
Dim RCnt As Long
Dim Msg As String
Set db = CurrentDb
Set rs = db.OpenRecordset("SELECT * FROM [QryMonthlyReport_Final] WHERE [QryMonthlyReport_Final].[ID_Jamat] = '" & BankName & "' ")
If rs.BOF = True Then
Exit Function
Else
rs.MoveFirst
rs.MoveLast
TotalNo_Field = rs.Fields.Count 'To Count No of Fields
RCnt = rs.RecordCount
Number_Field = 0
rs.MoveFirst
' Do
Name_Field_DB = rs.Fields(FieldNo).Name ' Finding the Name of The field Debit
' Debug.Print Name_Field_DB
MonthTranscation= rs.Fields(Name_Field_DB).Value
End If
Set rs = Nothing
Set db = Nothing
End Function
i have created a function that will populate the values in a report from a query
if i set month value in query as "JULY" then the report shows all the values and below function runs perfectly. as shown below
the report shows all the values...without error
Then added a form with combo to select the month from the list as shown below
and Open the report, it gives error on the same function
Below is the code, kindly help me why this is happening and how could i get solve that issue
Function MonthTranscation(BankName As String, FieldNo As Integer) As Long
Dim Name_Field_DB, Name_Field As String
Dim Amount_Field As String
Dim TotalNo_Field, Number_Field As Integer
Dim RCnt As Long
Dim Msg As String
Set db = CurrentDb
Set rs = db.OpenRecordset("SELECT * FROM [QryMonthlyReport_Final] WHERE [QryMonthlyReport_Final].[ID_Jamat] = '" & BankName & "' ")
If rs.BOF = True Then
Exit Function
Else
rs.MoveFirst
rs.MoveLast
TotalNo_Field = rs.Fields.Count 'To Count No of Fields
RCnt = rs.RecordCount
Number_Field = 0
rs.MoveFirst
' Do
Name_Field_DB = rs.Fields(FieldNo).Name ' Finding the Name of The field Debit
' Debug.Print Name_Field_DB
MonthTranscation= rs.Fields(Name_Field_DB).Value
End If
Set rs = Nothing
Set db = Nothing
End Function