Error in code

bknight
BronzeLounger
Posts: 1379
Joined: 08 Jul 2016, 18:53

Error in code

Post by bknight »

I have this code snippet used in Access

Code: Select all

If Fld3 = strCurSymbol And Fld4 = strCurCon And fld5 Is Null Then
I get an error. Object required.
All the conditions are true. I did attempt to to add Fld5.Value is null same result.
All Fld(n) are defined and set previously. I received the error after adding "fld5 Is Null", so it is there I suspect the error.
You do not have the required permissions to view the files attached to this post.

User avatar
HansV
Administrator
Posts: 78438
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: Error in code

Post by HansV »

You can use

fld5 Is Null

in a query/SQL, but not in VBA. Change it to

IsNull(fld5)
Best wishes,
Hans

bknight
BronzeLounger
Posts: 1379
Joined: 08 Jul 2016, 18:53

Re: Error in code

Post by bknight »

I'm not sure of why the difference, but that got by the error. The logic is wrong now as the loop continued and is supposed to stop when that condition is true.
Thanks

User avatar
HansV
Administrator
Posts: 78438
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: Error in code

Post by HansV »

If you want to exit the loop if the conditions on that line are true, then change it to

Code: Select all

            If Fld3 = ... Then
                Exit For
            Else
                ...
Best wishes,
Hans

bknight
BronzeLounger
Posts: 1379
Joined: 08 Jul 2016, 18:53

Re: Error in code

Post by bknight »

I changed the last condition IsNull(Fld12) to an Or instead of an And, that makes the loop stop as I wished it to do. Opening records can never have a value in Fld12 = Profit, only in closing records.