Solved

How open form with certain circumstances

Posted on 2014-01-09
2
344 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 120

Accepted Solution

by:
Rey Obrero (Capricorn1) earned 500 total points
ID: 39769728
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 37

Expert Comment

by:PatHartman
ID: 39769976
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

Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article describes a method of delivering Word templates for use in merging Access data to Word documents, that requires no computer knowledge on the part of the recipient -- the templates are saved in table fields, and are extracted and install…
If you need a simple but flexible process for maintaining an audit trail of who created, edited, or deleted data from a table, or multiple tables, and you can do all of your work from within a form, this simple Audit Log will work for you.
In Microsoft Access, when working with VBA, learn some techniques for writing readable and easily maintained code.
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…

688 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