Form Open/Close causing events to not fire


P

Pat

I use a form to display a selection of employees that is opened by double
clicking on the employee number field. Once the user clicks on the record
selector (employee form), I set the employee number on the previous form.
That works, but the before_update event is not being fired. If I do not call
the employee form with the double click and just enter a valid employee
number, the event fires normally.

This is the code from the empoyee form:
[Forms]![frmMaintainVPN].EmpNum.Value = Me.EmpNum.Value
DoCmd.Close acForm, Me.Name

I am calling the employee form from the main form with the following code;

Private Sub EmpNum_DblClick(Cancel As Integer)
If (Me.NewRecord) Then
DoCmd.OpenForm "frmListEmployees", acNormal
End If
End Sub


I am open to all suggestions .....
 
Ad

Advertisements

D

Dirk Goldgar

Pat said:
I use a form to display a selection of employees that is opened by double
clicking on the employee number field. Once the user clicks on the record
selector (employee form), I set the employee number on the previous form.
That works, but the before_update event is not being fired. If I do not
call
the employee form with the double click and just enter a valid employee
number, the event fires normally.

This is the code from the empoyee form:
[Forms]![frmMaintainVPN].EmpNum.Value = Me.EmpNum.Value
DoCmd.Close acForm, Me.Name

I am calling the employee form from the main form with the following code;

Private Sub EmpNum_DblClick(Cancel As Integer)
If (Me.NewRecord) Then
DoCmd.OpenForm "frmListEmployees", acNormal
End If
End Sub


Data updates that are performed by code do not normally fire any events --
only user interaction will fire the BeforeUpdate or AfterUpdate event. If
there is code in the BeforeUpdate event of the EmpNum field on form
frmMaintainVPN, and you need that code to execute, you can change the
declaration of the EmpNum_BeforeUpdate event prcoedure to make it Public
instead of Private, and then call it like this:

Dim intCancel As Integer

Call Forms!frmMaintainVPN.EmpNum_BeforeUpdate(intCancel)

Is the BeforeUpdate event the right event for you to be using? If you're
going to set the field from code, you won't be able to cancel the event, so
maybe you should be using the control's AfterUpdate event instead.
 
P

Pat

I'm not sure if it is the right event. My intent is when the user enters the
employee number either manually or by selection from the list, when they tab
to the next field I want to populate the remaining fields with data from the
employee table. Currently if they manually enter the eployee number it will
work. But since I added the double_click event to open the other form, is
when I started to have this problem.

Dirk Goldgar said:
Pat said:
I use a form to display a selection of employees that is opened by double
clicking on the employee number field. Once the user clicks on the record
selector (employee form), I set the employee number on the previous form.
That works, but the before_update event is not being fired. If I do not
call
the employee form with the double click and just enter a valid employee
number, the event fires normally.

This is the code from the empoyee form:
[Forms]![frmMaintainVPN].EmpNum.Value = Me.EmpNum.Value
DoCmd.Close acForm, Me.Name

I am calling the employee form from the main form with the following code;

Private Sub EmpNum_DblClick(Cancel As Integer)
If (Me.NewRecord) Then
DoCmd.OpenForm "frmListEmployees", acNormal
End If
End Sub


Data updates that are performed by code do not normally fire any events --
only user interaction will fire the BeforeUpdate or AfterUpdate event. If
there is code in the BeforeUpdate event of the EmpNum field on form
frmMaintainVPN, and you need that code to execute, you can change the
declaration of the EmpNum_BeforeUpdate event prcoedure to make it Public
instead of Private, and then call it like this:

Dim intCancel As Integer

Call Forms!frmMaintainVPN.EmpNum_BeforeUpdate(intCancel)

Is the BeforeUpdate event the right event for you to be using? If you're
going to set the field from code, you won't be able to cancel the event, so
maybe you should be using the control's AfterUpdate event instead.

--
Dirk Goldgar, MS Access MVP
www.datagnostics.com

(please reply to the newsgroup)
 
Ad

Advertisements

P

Pat

I found the answer after digging a little more. As Dirk said, the event will
not fire if updated by vb code or a macro. It will only fire if the data us
manually entered. Just what I saw. I used the LostFocus to handle my
situation and it works fine. Of course I have to handle many situations that
can occur when focus is lost.

Pat said:
I'm not sure if it is the right event. My intent is when the user enters the
employee number either manually or by selection from the list, when they tab
to the next field I want to populate the remaining fields with data from the
employee table. Currently if they manually enter the eployee number it will
work. But since I added the double_click event to open the other form, is
when I started to have this problem.

Dirk Goldgar said:
Pat said:
I use a form to display a selection of employees that is opened by double
clicking on the employee number field. Once the user clicks on the record
selector (employee form), I set the employee number on the previous form.
That works, but the before_update event is not being fired. If I do not
call
the employee form with the double click and just enter a valid employee
number, the event fires normally.

This is the code from the empoyee form:
[Forms]![frmMaintainVPN].EmpNum.Value = Me.EmpNum.Value
DoCmd.Close acForm, Me.Name

I am calling the employee form from the main form with the following code;

Private Sub EmpNum_DblClick(Cancel As Integer)
If (Me.NewRecord) Then
DoCmd.OpenForm "frmListEmployees", acNormal
End If
End Sub


Data updates that are performed by code do not normally fire any events --
only user interaction will fire the BeforeUpdate or AfterUpdate event. If
there is code in the BeforeUpdate event of the EmpNum field on form
frmMaintainVPN, and you need that code to execute, you can change the
declaration of the EmpNum_BeforeUpdate event prcoedure to make it Public
instead of Private, and then call it like this:

Dim intCancel As Integer

Call Forms!frmMaintainVPN.EmpNum_BeforeUpdate(intCancel)

Is the BeforeUpdate event the right event for you to be using? If you're
going to set the field from code, you won't be able to cancel the event, so
maybe you should be using the control's AfterUpdate event instead.

--
Dirk Goldgar, MS Access MVP
www.datagnostics.com

(please reply to the newsgroup)
 

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