Solved

How open form with certain circumstances

Posted on 2014-01-09
2
343 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 36

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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Preparing an email is something we should all take special care with – especially when the email is for somebody you may not know very well. The pressures of everyday working life stacked with a hectic office environment can make this a real challen…
AutoNumbers should increment automatically, without duplicates.  But sometimes something goes wrong, and the next AutoNumber value is a duplicate.  This article shows how to recover from this problem.
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

730 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