Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Open form in Add or Edit mode depending on data 1

Status
Not open for further replies.

JohnVogel

Programmer
Apr 19, 1999
117
US
I am creating a simple database to track fuel for a gas station. When a delivery comes in, I have a form which allows the clerk to enter the amount of fuel before and after the deliver. I would like for the form to come up with the present day, as well as making sure that A.) There is no data entered for that day already and B.) If there is data for the day, then display this data, otherwise simply display a form allowing them to enter the data.

How can I check to see if there is already data entered for Date() (that is today)? And how do I open a form in Add or Edit mode (depending on whether or not there is already data)...

I hope this question is clear enough, I am totally brain-logged right now, and the only thing I could think of (off-hand) is to maybe see if anyone in Tek-Tips might know what I am trying to do...

TIA


John Vogel
john@thecompuwizard.com
 
You can Try this John, add this code to the sub form open event.

I would probably make a pass-through form with something like this in the on_open event.

Private Sub Form_Open(Cancel As Integer)
If IsNull(DLookup("date", "tblsource", "date = #" & Date & "#")) Then
DoCmd.OpenForm "frm_entry", acNormal, , , acFormAdd
Else
DoCmd.OpenForm "frm_entry", acNormal, , "date = #" & Date & "#", acFormEdit
End If

DoCmd.Close acForm, Me.Name
End Sub


Hope this helps
Charles
cbrumagem@cbf.com
 
Charles,

Sorry it took me so long to reply to your post here... your suggestion worked great, and I appreciate it!

If it weren't for people like yourself, I'd probably be beating my head against the wall ;)

John Vogel
john@thecompuwizard.com
 
Additional question:

How can I force the form to open in add-mode and be ready to accept new data (a new record in the associated table)

This works great from the switchboard with opening the form in 'add-mode' , but how to enforce it when opening the form through an action button or macro?

T. Blom
Information analyst
tbl@shimano-eu.com
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top