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 Rhinorhino on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Problem with Form_AfterInsert Property

Status
Not open for further replies.

jdegeorge

Programmer
Joined
Mar 19, 2002
Messages
1,313
Location
US
Hello, Tek-Tips Wizards!!!

I have a form with some code in the Form_AfterInsert property on a DATA ENTRY form.

If I enter information in the fields and tab through to the next new record, the Form_AfterInsert code works just fine.

However, because of some field defaults, it isn't necessary to tab all the way through or enter information in all the fields. So, if the user hits the CLOSE button the code behind the Form_AfterInsert property doesn't run.

Here's the code for the close button:

[tt]DoCmd.Close acForm, Me.NAME, acSaveYes
[Forms]![frmGapMenu].Visible = True[/tt]

The Form_AfterInsert property code is too complicated to post here, and I don't believe it's necessary to do that.

Shouldn't the Form_AfterInsert property code run automatically when the CLOSE button is clicked?

Please help!


Jim DeGeorge [wavey]
 
Hi

I put the code from the Form_AfterInsert property in the code behind the CLOSE button (before the "DoCmd.Close acForm, Me.NAME, acSaveYes" line) and it worked fine.

Thanks for those of you who were workign on a solution!

Jim DeGeorge [wavey]
 
Part II...

It didn't work 100%. One of my testers found a problem when tabbing through to a new records versus closing the form with the close form command.

Anywho, I just modifed this part of the code:

[tt]If IsNull(Me![ctlGap#]) Then
Me![ctlGap#].SetFocus
Me![ctlGap#] = Me![ctlTempID#]
Me![ctlGap_Status].SetFocus
SendKeys "{TAB}", False
End If[/tt]

to

[tt]If IsNull(Me![ctlGap#]) Then
Dim rst As DAO.Recordset
Dim strCrit As String
strCrit = "[Description] = '" & Me![ctlGapDescription] & "' AND [Conversion] = '" & Me![ctlConversion] & "'"
Set rst = Me.RecordsetClone
With rst
.FindFirst strCrit
.Edit
.Fields("Gap#") = Me![ctlTempID#]
.Update
End With
Set rst = Nothing
Me![ctlGap_Status].SetFocus
SendKeys "{TAB}", False
End If[/tt]

and it's working! Thanks everyone for taking a look at this.

It's times like this when I wish I could give myself a star! It's always rewarding to solve your own problems.


Jim DeGeorge [wavey]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top