Why an Insert does not Occur

E

Eka1618

Hello,

I have a form that contains several subforms that are inside a tab control.
I also have other subforms on the parent form in other spots as well.

Usually when I go from one subform to another, an insert occurs. For
instance if I fill in all data in frm1 and move to frm2, an insert into a
table will occur in frm1.

My problem is with the subforms that are inside the tab control. Lets say I
fill in data in frm3 (which is in the tab), and then move back to the parent
for (or any other form for that matter) the insert does not occur.

I am trying to check to see if data was entered in each form before a user
click the send button. I am tracking this by seeing if the AfterInsert event
fired on the subforms. Can anybody tell my why this event does not fire? Does
anyone know? I do not understand why it fires for some subforms and not
others...

Any help would be greatly appreciated, Thank You!
 
E

Eka1618

I do know that using me.dirty = false will force a disk write, but I do not
know when to use this... I have tried using it on form.LostFocus since I am
moving from a subform to another or its parent form, but this is not working.

any suggestions would be great, thank you!
 
J

John W. Vinson

Hello,

I have a form that contains several subforms that are inside a tab control.
I also have other subforms on the parent form in other spots as well.

The tab control is irrelevant in this case - it just manages screen position,
not subform events.
Usually when I go from one subform to another, an insert occurs. For
instance if I fill in all data in frm1 and move to frm2, an insert into a
table will occur in frm1.

Well... not exactly. Setting focus to a subform forces the mainform record to
be saved, if it's dirty; losing focus from a subform forces the subform's
record to be saved, if it's dirty. Neither event will (or should) cause a new
record to be created and inserted.
My problem is with the subforms that are inside the tab control. Lets say I
fill in data in frm3 (which is in the tab), and then move back to the parent
for (or any other form for that matter) the insert does not occur.

I am trying to check to see if data was entered in each form before a user
click the send button. I am tracking this by seeing if the AfterInsert event
fired on the subforms. Can anybody tell my why this event does not fire? Does
anyone know? I do not understand why it fires for some subforms and not
others...

I don't either based on the description. The AfterInsert event fires after the
AfterUpdate event of a subform if the user has entered data into the "new
record"; it will not fire if the user does nothing in the subform. What's the
code in the "Send" button? Each form's BeforeUpdate event can be used to
ensure that the data entered on that form (whether mainform or subform) is
valid; but it sounds like your users may be just skipping over a subform
altogether. The only way to detect this kind of error is to have code in your
button event to (say) do a DLookUp on the child table to see if a record has
been entered; as far as Access is concerned, putting nothing into a subform is
perfectly legitimate and will not cause any event to fire.
 
E

Eka1618

Hi John,

Below are samples of my code. I cannot seem to trigger the event that
detects wether or not the subform lost focus. Not all subforms in the tab
control will have data entered. They all have a record source of the same
table though.

The lostFocus or beforeUpdate/afterUpdate events only occur when I move from
one of these subforms to the next (inside the tab) When I move from the forms
inside the tab to other subforms on the parent form or the parent form
itself, these events do no fire.

This is code for btnSend (parent form):

Public Sub btnSend_Click()
Dim teesEmail As String
Dim torsEmail As String
Dim varItem As Variant

strValid = CheckFormValues(Me)

If strValid <> vbNullString Then
MsgBox "There are items on this form that were left blank. Please
review and fill in missing value."
ElseIf lockTest = True And enteredKeyTool = False Then
MsgBox "You have not entered a Key for this request."
ElseIf lugTool = True And enteredKeyTool = False Then
MsgBox "You have chosen to include a tool with the Lug and did not
enter Tool information for this request."
ElseIf checkTest = False Then
MsgBox "You must have atleast one test associated with this request."
Else
For Each varItem In Me.lboRequestee.ItemsSelected
teesEmail = teesEmail & Me.lboRequestee.Column(2, varItem)
Next varItem

For Each varItem In Me.lboRequestor.ItemsSelected
torsEmail = torsEmail & lboRequestor.Column(2, varItem)
Next varItem

Call SetRequesteeEmailProp(teesEmail) ' found in modProperties
Call SetRequestorEmailProp(torsEmail) ' found in modProperties

Call SendRequest(Me)
DoCmd.Close acForm, "frmOneKey", acSaveNo
End If
End Sub


Here is the code for a subForm inside the tab:

Private Sub Form_AfterInsert()
checkTest = True ' a global boolean variable
End Sub

Private Sub Form_BeforeUpdate(Cancel As Integer)

strValid = CheckFormValues(Me)

If strValid <> vbNullString Then
MsgBox "All fields must be filled before Continuing"
Cancel = True
End If
End Sub



Let me know what you think, Thank you!
 
E

Eka1618

Well, I believe I may have solved my problem.

The beforeUpdate event occurs before the brforeInsert event right? Well, I
figured since I need to check the same code during an insert and during an
update; I would put the code in the beforeUpdate event only. I do not
understand why I didn't try this sooner, but I used the code in both events
and it finally works. I do not understand why though. If beforeUpdate always
occurs before a beforeInsert then using the code in the beforeUpdate should
have done the trick, right?

anywho, hopefully I do not have anymore problems with this.
 
E

Eka1618

I still would like to figure out how to trigger the time at which the form
looses focus though, I'm still having trouble with this when it comes to the
subforms inside the tab control.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top