When the Look up value under the [Status]='For Signature' do not exist in the current record, the code returns an error where it says error [disc] = 'books' cannot be found error..however the code works when the look up [status] value is on the list/record.
I want to have the code to continue the execution and return empty values even the look up [status] value do not exist anymore.
Please help, thanks
I want to have the code to continue the execution and return empty values even the look up [status] value do not exist anymore.
Please help, thanks
Code:
Public Function fAppendIANum3(Disc) As String
Dim intNoOfIA3 As String, strNames3 As String
intNoOfIA3 = DCount("*", "TBXQuery", "Disc AND [Status]=""For Signature""")
If intNoOfIA3 = 0 Then
fAppendIANum3 = DLookup("[IA_Number_]", "TBXQuery", "[Disc]=" & Disc & "' AND [Status]='For Signature'")
Exit Function
Else
Dim db As DAO.Database
Dim qdf As DAO.QueryDef
Dim rs2 As DAO.Recordset
Dim MyRS As String
MyRS = "SELECT [TBXQuery].* " & _
"FROM [TBXQuery] " & _
"WHERE [Disc] = [which_id] AND [Status]='For Signature'"
Set db = CurrentDb
Set qdf = db.CreateQueryDef(vbNullString, MyRS)
qdf.Parameters("which_id") = Disc
Set rs2 = qdf.OpenRecordset
rs2.FindFirst ("[Status]= 'For Signature'")
Do While Not rs2.EOF
If Len(strNames3) = 0 Then
strNames3 = rs2![IA_Number_]
Else
strNames3 = strNames3 & ", " & rs2![IA_Number_]
End If
rs2.MoveNext
Loop
fAppendIANum3 = strNames3
End If
rs2.Close
End Function
Comment