.FindFirst

T

Tom W

Abbreviated code:

Set rst = db.OpenRecordset("qryFORECAST", dbOpenDynaset)
mCP = ![CONTID]+![PRINID]
Set rst1 = dbOpenRecordset("tempFORECAST", dbOpenTable)
rst1.FindFirst "![CONTID]+![PRINID]" = mCP

The above code fails to find the record.

What can I do to make the process work?
 
G

Guest

Corrected code:

Set rst1 = dbOpenRecordset("tempFORECAST", dbOpenTable)
mCP = ![CONTID]+![PRINID]
Set rst = db.OpenRecordset("qryFORECAST", dbOpenDynaset)
rst.FindFirst "![CONTID]+![PRINID]" = mCP
 
J

John Spencer (MVP)

Not sure, but I would try

rst.FindFirst "[CONTID]+[PRINID] = " & mCP

But why not


rst.FindFirst "[CONTID]= " & rst1("ContID") & " AND [PRINID] = " & rst1("PrinID")



Corrected code:

Set rst1 = dbOpenRecordset("tempFORECAST", dbOpenTable)
mCP = ![CONTID]+![PRINID]
Set rst = db.OpenRecordset("qryFORECAST", dbOpenDynaset)
rst.FindFirst "![CONTID]+![PRINID]" = mCP
-----Original Message-----
Abbreviated code:

Set rst = db.OpenRecordset("qryFORECAST", dbOpenDynaset)
mCP = ![CONTID]+![PRINID]
Set rst1 = dbOpenRecordset("tempFORECAST", dbOpenTable)
rst1.FindFirst "![CONTID]+![PRINID]" = mCP

The above code fails to find the record.

What can I do to make the process work?
.
 
G

Guest

John,
Thank you very much for your response. I will try them
out.
-----Original Message-----
Not sure, but I would try

rst.FindFirst "[CONTID]+[PRINID] = " & mCP

But why not


rst.FindFirst "[CONTID]= " & rst1("ContID") & " AND [PRINID] = " & rst1("PrinID")



Corrected code:

Set rst1 = dbOpenRecordset("tempFORECAST", dbOpenTable)
mCP = ![CONTID]+![PRINID]
Set rst = db.OpenRecordset("qryFORECAST", dbOpenDynaset)
rst.FindFirst "![CONTID]+![PRINID]" = mCP
-----Original Message-----
Abbreviated code:

Set rst = db.OpenRecordset("qryFORECAST", dbOpenDynaset)
mCP = ![CONTID]+![PRINID]
Set rst1 = dbOpenRecordset("tempFORECAST", dbOpenTable)
rst1.FindFirst "![CONTID]+![PRINID]" = mCP

The above code fails to find the record.

What can I do to make the process work?
.
.
 
T

Tim Ferguson

rst1.FindFirst "![CONTID]+![PRINID]" = mCP

I am not quite sure what this is meant to do -- adding ID numbers together
is an (ahem) unusual approach. If they are text values, then it's safer to
use an ampersand (&) and you'll need to delimit the whole lot with quote
marks:

"CONTID & PRINID = """ & mCP & """"

Then again, if you are aiming to match the two values, you have a potential
bug telling the difference between "1" & "12" and "11" & "2". The even
safer approach is to use two comparisons:

rst1.FindFirst _
"ContID = """ & !ContID & """ AND PrinID = """ & !PrinID & """"

Hope that helps


Tim F
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top