don't close form if ...

deekras

Registered User.
Local time
Today, 22:24
Joined
Jun 14, 2000
Messages
169
i have a datasheet. when the user doubleclicks on the member number, another form opens where the user can enter details about the member. when the user goes to the next member number on the datasheet, the detail form closes. when she double clicks the member number, it opens with the second member's info.

my question is: on the details form, i have some fields that must be filled if one of the fields has a certain value. (if [attempt] = "call back later" then user must fill in a call back time) i want to make sure that the user fills it in.

so far i have tried:

Private Sub Form_Close()
If Me.attempt = "call back later" And IsNull(Me.[attempt_call_back date]) Then
MsgBox "You must enter a call back date.", vbOKOnly, "Call Back details"
DoCmd.GoToControl "attempt_call_back date"
Exit Sub
End If

the MSgbox comes us, it quickly goes to the correct field and then quickly closes the form.

i tried putting this code behind the [member number] field:

If IsFormOpen("details") = True Then
If Forms![details]![attempt] = "call back later" And IsNull(Forms![details]![attempt_call_back_date]) Then
MsgBox "You must enter a call back date.", vbOKOnly, "Call Back details"
Forms![details].[attempt_call_back_date].SetFocus
Else
DoCmd.Close acForm, "details", acSaveYes
End If
End If

this works as far as not closing the details form, but the cursor does not blink in the [attempt_call_back_date] field AND if the user closes the details form with the X, i cannot make sure that the info is entered.

how can i make sure that the user enters all necessary info before the form closes?
 
Hi,

Ok the set focus is wrong do it like this:

Forms!details!name of text box.SetFocus

where name of text box is the name of the text box that related to the field.


go to properties and get rid of the X to close form, you'll find it in the formate tab.

Now create a close form button and do an if else statement in the code like this

If IsNull(Forms![details]![attempt_call_back_date]) then

msgbox "enter the details fool!"

else

docmd.close


Hope this helps
 
thanks, but the users asked me not to have a close button. they prefer to have it the way i have it set up- when they go to the next member number in the datasheet the details form closes.
 
i changed the setfocus line

but still the focus (blinking cursor) is on the member number in the datasheet
 
Hi,

Then add the code to the event that closes the form,

I would stear clear of the datasheet personally, with a form you can do what you want, but with a datasheet you are more limited.
 
You should use the BeforeUpdate event of the form and Cancel=true if the condition is not met.

DoCmd.Close acForm, "details", acSaveYes
is saving the form not the Record
 

Users who are viewing this thread

Back
Top Bottom