Pausing Code to wait for Date Entry (1 Viewer)

music_al

Registered User.
Local time
Today, 01:09
Joined
Nov 23, 2007
Messages
200
Hi

I have a procedure which creates a new contract for an employee in the Contracts table (tbl_Contracts)

After some fields have been set a form appears in which the user will enter the Start Date of the new contract. This is done by the code...

Code:
    DoCmd.OpenForm "frm_Contract_Start_Date"
 
more code here that works out the End Date based on the duration of the contract

The problem is, the code AFTER the DoCmd line is then executed but I don't want it to. I want it to wait until a date has been passed from the form that is opened.

How would I pause the code there to make it wait for the date to be entered ?

Thank you in advance.
 

isladogs

MVP / VIP
Local time
Today, 01:09
Joined
Jan 14, 2017
Messages
18,287
Several methods - for example

1. Add an If ....End If condition
Code:
If Nz(Me.DateField,"")="" Then Exit Sub

2. Split your code into two.
Put the code that follows date entry into the date field after update event. If necessary create 2 separate procedures
 

Minty

AWF VIP
Local time
Today, 01:09
Joined
Jul 26, 2013
Messages
10,381
An alternative is to open the form in the modal popup / dialog mode.

That suspends all code execution in the calling form until the Modal form is closed.
 

music_al

Registered User.
Local time
Today, 01:09
Joined
Nov 23, 2007
Messages
200
Several methods - for example....

2. Split your code into two.
Put the code that follows date entry into the date field after update event. If necessary create 2 separate procedures

This is what I had done originally but I never liked the method.
 

isladogs

MVP / VIP
Local time
Today, 01:09
Joined
Jan 14, 2017
Messages
18,287
Fair enough though to me its the most flexible approach.
 

The_Doc_Man

Immoderate Moderator
Staff member
Local time
Yesterday, 19:09
Joined
Feb 28, 2001
Messages
27,436
Other than the appearance of the dialog, you could just pop up an input box to get the date at the point where you need it.
 

music_al

Registered User.
Local time
Today, 01:09
Joined
Nov 23, 2007
Messages
200
I added this to the end of the line of code...

Code:
    DoCmd.OpenForm "frm_Contract_Start_Date", , , , , acDialog      
    MsgBox Contract_Start_Date     'Added this just to test

And the MsgBox is still appearing at the same time the form is appearing. Have I missed something ?
 

music_al

Registered User.
Local time
Today, 01:09
Joined
Nov 23, 2007
Messages
200
Other than the appearance of the dialog, you could just pop up an input box to get the date at the point where you need it.

Is there any way of making the input box show a calendar when the user clicks inside the text box ?
 

isladogs

MVP / VIP
Local time
Today, 01:09
Joined
Jan 14, 2017
Messages
18,287
Taking your last 2 posts together

1. You cold delay your message box appearing by using a timer event to run it.
Set the interval to 1000 for a one second delay.
Add msgbox code to that event and then set time interval =0 so it only runs once.

2 No you can't. You would need to create your own popup form instead of using an input box
 

music_al

Registered User.
Local time
Today, 01:09
Joined
Nov 23, 2007
Messages
200
It looks like its working now. Maybe I didn't save the Module before running the code again.
 

Users who are viewing this thread

Top Bottom