Re: Where do I put the code main or subform?
- From: Tim <Tim@xxxxxxxxxxxxxxxxxxxxxxxxx>
- Date: Wed, 25 Oct 2006 12:03:02 -0700
Well, I have problems here. When I intentionally leave [txtField1] blank and
click on the Next button of the built-in Access navigaton (on the subform),
it does pop up my error message and the SetFocus set the cursor back to this
field. However, I, intentionally, click on the next button of the Access
navigation of the subform again, this time, it is advanced to the next
record. This is not right!
Also, when I leave the [txtField1] blank and click on the next button of the
Main form, the error message pops up and I click the OK button of the
message, it advances to the next record. Why does it behave like this?
Thank you for your help
tim
"Allen Browne" wrote:
No loop is needed..
Cancelling Form_BeforeUpdate means the user is stuck editing the form. Once
they have entered the data, it will try to save, which triggers
Form_BeforeUpdate again, which runs your test. If the data is still not
right, they are still stuck editing the form, and so on.
--
Allen Browne - Microsoft MVP. Perth, Western Australia.
Tips for Access users - http://allenbrowne.com/tips.html
Reply to group, rather than allenbrowne at mvps dot org.
"Tim" <Tim@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote in message
news:420ECE90-F33D-4778-AC3D-5879B5C33475@xxxxxxxxxxxxxxxx
Thanks, Allen. To answer your questions...
1. Is the subform bound to a table/query?-Yes.
2. Is txtField1 bound to a field in the table?-Yes.
3. Is the form's BeforeUpdate property set to [Event Procedure]-Yes.
4. You did put this into the Before Update of the subform's module (not-Yes.
the
main form's module)?
5. Temporarily comment out the error handler, and add a line to the top-Good practice!
of
the procedure to verify the code is running, and add a Stop. When it runs
you can then press F8 repeatedly to step through the lines of code and
trace
what's going on.
6. The Exit Sub part need to be outside the IF block.-All right!
7. You can use Me to refer to the current form.-I do put IsNull(Me.txtField1), but in the following line below it, I have
to refer the
main form also. If not, there is an error message saying that the program
can't find the form "frmSubform" referred to in a macro expression or VB
code.
8. After these changes, does the code compile (Compile on Debug menu)?-Yes, but I would like to add a loop so that the message keeps repeat
until
the user will have to enter something in the field. I have tried to do the
following code,
If IsNull(Me.txtField1) Then
MsgBox "You must enter Field1", vbOKOnly, "Missing Field!"
Do Until Not IsNull(Me.txtField1) And Me.txtField1 <> ""
Forms![frmMain]![frmSubform]![txtField1].SetFocus
Loop
End If
------
However, I get the infinitive loop. Can you please help me to fix the bug?
"Tim" <Tim@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote in message
news:FD4E6F89-970F-459B-8530-E22BD389CAA2@xxxxxxxxxxxxxxxx
Thanks, Allen. I have written some VBA codes into my subform
BeforeUpdate
event and tested it. However, when I intentionally left [txtField1]
blank
and
click the Access built-in navigation of the subform to advance to the
next
record, nothing is happen; i.e., there is no error message and the form
shows
the next record. Same thing happened when I clicked on the built-in
navigation to advance to the next record of the main form. Do you know
what
is wrong with the following codes:
Private Sub Form_BeforeUpdate(Cancel As Integer)
On Error GoTo PROC_ERR
If IsNull([Forms]![frmSubform]![txtField1]) Then
MsgBox "You must enter Field1", vbOKOnly, "Missing Field!"
Forms![frmSubform]![txtField1].SetFocus
Exit Sub
End If
PROC_ERR:
MsgBox Err.Description
Resume Next
End Sub
***********
When I tried to refer the main form and then the subform into the code,
there is still no error message it supposed to pop up!
- Follow-Ups:
- Re: Where do I put the code main or subform?
- From: Allen Browne
- Re: Where do I put the code main or subform?
- References:
- Re: Where do I put the code main or subform?
- From: Allen Browne
- Re: Where do I put the code main or subform?
- From: Allen Browne
- Re: Where do I put the code main or subform?
- From: Tim
- Re: Where do I put the code main or subform?
- From: Allen Browne
- Re: Where do I put the code main or subform?
- From: Allen Browne
- Re: Where do I put the code main or subform?
- From: Tim
- Re: Where do I put the code main or subform?
- From: Allen Browne
- Re: Where do I put the code main or subform?
- Prev by Date: Re: Msgbox response action
- Next by Date: Re: Adding new records in Popup form
- Previous by thread: Re: Where do I put the code main or subform?
- Next by thread: Re: Where do I put the code main or subform?
- Index(es):