Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Multiple if's

Status
Not open for further replies.

gneff

Technical User
Aug 24, 2002
15
US
I am trying to get this code to work
If Forms![COJOBMASTER]![COTAKEOFF]![ITEMNO] <> DMax(&quot;[ITEMNO]&quot;, &quot;COTAKEOFF&quot;,&quot;[COJOBID] = &quot; & Forms![COJOBMASTER]![COTAKEOFF]![COJOBID]) And Forms![COJOBMASTER]![COTAKEOFF]![CONumber] <> DMax(&quot;[CONumber]&quot;,
&quot;COTAKEOFF&quot;, &quot;[COJOBID] = &quot; & Forms![COJOBMASTER]![COTAKEOFF]![COJOBID])Then
DoCmd.GoToRecord , , acNext
End If

I am trying to do a simple thing, this is for a forward button on the form to scroll through the items, I have two variables as you can see. Any help would be appreciated.
 
Typically when I have a long complex program, I break it into variables. It makes it easier to pin-point the problems as well as document.

Try setting up some variables..
lnVar1 = Forms![COJOBMASTER]![COTAKEOFF]![ITEMNO]
lnVar2 = DMax(&quot;[ITEMNO]&quot;, &quot;COTAKEOFF&quot;,&quot;[COJOBID] = &quot; & Forms![COJOBMASTER]![COTAKEOFF]![COJOBID])

lnVar3 =Forms![COJOBMASTER]![COTAKEOFF]![CONumber]
lnVar4 = DMax(&quot;[CONumber]&quot;,&quot;COTAKEOFF&quot;, &quot;[COJOBID] = &quot; & Forms![COJOBMASTER]![COTAKEOFF]![COJOBID])

Then integrate into ur IF Statement.

Use msgbox(lnVar?) or DEbug to see values ...

htewh Steve Medvid
&quot;IT Consultant & Web Master&quot;
e-Mail: Stephen_Medvid@GMACM.com

Chester County, PA Residents
Please Show Your Support...
 
I would get away from the DMax, etc functions and use recordsets. They require more code but are much faster. Also, I'd actually use variables, as this will make the code easier to read.

Here's how I'd rewrite this code (this is untested aircode, you may well have to tweak it a bit):

dim db as dao.database
dim strSql as string
dim rst as dao.recordset
dim iItemNo as integer
dim iCoNo as integer

set db = currentdb

strsql = &quot;SELECT Max(ITEMNO) as MaxItemNo FROM COTAKEOFF WHERE COJOBID = &quot; & Forms![COJOBMASTER]![COTAKEOFF]![COJOBID]
set rst = db.openrecordset(strsql, dbopensnapshot)
iItemNo = rst(&quot;MaxItemNo&quot;)

strsql = &quot;SELECT Max(CONumber) as MaxCoNo FROM COTAKEOFF WHERE COJOBID = &quot; & Forms![COJOBMASTER]![COTAKEOFF]![COJOBID]
set rst = db.openrecordset(strsql, dbopensnapshot)
iCoNo = rst(&quot;MaxCoNo&quot;)

If Forms![COJOBMASTER]![COTAKEOFF]![ITEMNO] <> iItemNo And Forms![COJOBMASTER]![COTAKEOFF]![CONumber] <> iCoNo Then
DoCmd.GoToRecord , , acNext
End If

db.close
set db = nothing
rst.close
set rst = nothing

===========
Also, because you've been good about not using spaces in your object names, you can get rid of the brackets. Also, I'd ditch the all CAPS in your object names, as that makes them harder to read (camelBack is usually easiest).

Hope this helps.

Jeremy =============
Jeremy Wallace
Designing, Developing, and Deploying Access Databases Since 1995

Take a look at the Developers' section of the site for some helpful fundamentals.
 
Thanks for the Help, I have fixed the problem by a very simple fix, I was using the [ITEMNO] variable and it was unnecesssary by dumping that portion and only using the [CONumber] it works fine. Thanks again
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top