Expected =

John Sh

Member
Local time
Today, 16:37
Joined
Feb 8, 2021
Messages
513
I have a test form with a single button that is used to test some new code.
All was working well until I added a boolean variable to the first function.
Now I am getting this "expected =" message when I add "true" or "false" to the calling sub.

The object of the exercise is to search a predefined range of tables for the occurrence, or otherwise, of a range of specific field values
The table "tableList" has the range of tables stored in it. The table "listTables" holds the results of "Searcher" for use in a yet to be built menu form.

Code:
Option Compare Database
Option Explicit

Private Sub Command22_Click()
    CheckAll ("boxno", true)    'entering ", true" here causes the error
End Sub

Private Function CheckAll(sField As String, bChanger As Boolean)    ' It was working before I entered " bChanger as boolean" but with type mismatches  in the _                                                                                                                                  "searcher" function
    Dim db As Database
    Dim rs1 As Recordset
    Dim rs2 As Recordset
    Dim nQuantity As Integer
    Set db = CurrentDb
    Set rs1 = db.OpenRecordset("listTables", dbOpenDynaset)
    Set rs2 = db.OpenRecordset("TableList", dbOpenSnapshot)
    rs2.MoveFirst
    If rs2!TableName = "Barry collier collection" Then
        rs2.MoveNext
    End If
    If sField = ("BoxNo" Or sField = "Bayno" Or sField = "shelfno") And rs2!TableName = "Reference collection" Then
        rs2.MoveNext
    End If
    Do
        nQuantity = Searcher(sField, rs2!TableName, bChanger)
        If nQuantity > 0 Then
            rs1.AddNew
            rs1!TableName = rs2!CommonName
            rs1!quantity = nQuantity
            rs1.Update
        End If
        rs2.MoveNext
    Loop While Not rs2.EOF
End Function

Private Function Searcher(sField As String, sForm As String, bChanger As Boolean) As Integer
    Dim sEquals As String
    sEquals = IIf(sField = "Genus" Or sField = "SpeciesEpithet", " = ''", " = 0 ")
    sEquals = IIf(bChanger, " > 0 ", sEquals)
    Searcher = DCount("*", sForm, sField & sEquals)
End Function
 
Code:
' for a simple call
CheckAll "boxno", True

' to pass the return value of the function (your function has none)
Dim vReturn As Variant
vReturn = CheckAll("boxno", True)
 
Code:
' for a simple call
CheckAll "boxno", True

' to pass the return value of the function (your function has none)
Dim vReturn As Variant
vReturn = CheckAll("boxno", True)
Thank you for that.
I've never encountered a problem with the brackets and no return value but it now works so thanks again, you time is much appreciated.
 

Users who are viewing this thread

Back
Top Bottom