Solved

How open form with certain circumstances

Posted on 2014-01-09
2
339 Views
Last Modified: 2014-01-10
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?
0
Comment
Question by:SteveL13
2 Comments
 
LVL 119

Accepted Solution

by:
Rey Obrero earned 500 total points
Comment Utility
if dcount("*", "NameOfTable","PetId=" & me.txtPetID)>0 then

DoCmd.OpenForm "frmRequestForPickup", acNormal, ,"[PetID]=" & me.txtPetID , , acWindowNormal


else

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

End if



if PetID is Text, use this


DoCmd.OpenForm "frmRequestForPickup", acNormal, ,"[PetID]='" & me.txtPetID & "'" , , acWindowNormal
0
 
LVL 34

Expert Comment

by:PatHartman
Comment Utility
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.
0

Featured Post

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

QuickBooks® has a great invoice interface that we were happy with for a while but that changed in 2001 through no fault of Intuit®. Our industry's unit names are dictated by RUS: the Rural Utilities Services division of USDA. Contracts contain un…
Describes a method of obtaining an object variable to an already running instance of Microsoft Access so that it can be controlled via automation.
Basics of query design. Shows you how to construct a simple query by adding tables, perform joins, defining output columns, perform sorting, and apply criteria.
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

763 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

7 Experts available now in Live!

Get 1:1 Help Now