Avatar of SteveL13
SteveL13
Flag for United States of America asked on

How open form with certain circumstances

I have a 2nd form which opens from a command button on a 1st form:

DoCmd.OpenForm "frmRequestForPickup", acNormal, , , acFormAdd, acWindowNormal

if the form has never been filled out before.

But if the form has been filled out before I want it to open and show that record which I suppose means it can't open with the acFormAdd in the code.

The way to determine if the form has been filled out before and there is a record entered already is via a field named "PetID".  If the table has a record with PetID matching the field txtPetID in form 1 then display the already existing record.

How?
Microsoft Access

Avatar of undefined
Last Comment
PatHartman

8/22/2022 - Mon
ASKER CERTIFIED SOLUTION
Rey Obrero (Capricorn1)

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
PatHartman

You don't actually need to do the dLookup().  Just open the form normally with a where argument.   If the record is found, the form will open to the found record.  If it wasn't found, the form will open to a new record.  So,
DoCmd.OpenForm "frmRequestForPickup", acNormal, ,"[PetID]=" & me.txtPetID , , acWindowNormal

Should do it.
I started with Experts Exchange in 2004 and it's been a mainstay of my professional computing life since. It helped me launch a career as a programmer / Oracle data analyst
William Peck