Modal Form: Form Load, Form Open, Form Activate events do not Fire 
Author Message
 Modal Form: Form Load, Form Open, Form Activate events do not Fire

I wish for a user to clik on a text box (or hit the enter key on the text
bok) and have a modal, dialog form open up that contains a listbox control.
The user will select from the listbox, hit an OK button and return to the
main form or Hit a cancel button and return to the main form.

Everything works fine except that whenever I open the dialog form
containing the listbox I want the listbox to be in an unselected state. The
first time I open the dialog form this is the state, but every subsequent
time the dialog form is opened the initial state of the listbox is selected
with the choice made from the previous selection.

Within the dialog form I have tried to code various events that would
guarnatee that the listbox on the modal form is in an unselected state, all
to no avail. Here is the code for the mainform text box that calls the modal
form.

DoCmd.OpenForm "frmListCategory", , , , , acDialog   open as dialog
    If SysCmd(acSysCmdGetObjectState, acForm, "frmListCategory") Then
        'Form is still open
        Me.txtCategoryName = Forms!frmListCategory!lstCategory.Column(1)
        Me.txtCategoryId = Forms!frmListCategory!lstCategory.Column(0)
        DoCmd.Close acForm, "frmListCategory", acSaveNo   I have set
option for no save, but form retains settings
    End If

Note that I have closed the modal form with the DoCmd.Close actions.
Nonetheless the next time the form is called, neither the Load, Open,
Activate, or Get Focus events seems to be called. I have tried coding in all
these events

Here is the code for the Modal form.

Private Sub Form_Load()
    Me.lstCategory.SetFocus
    Me.lstCategory.Selected(0) = True
    Me.lstCategory.Selected(0) = False
End Sub

Private Sub cmdCancel_Click()
    DoCmd.Close acForm, Me.FormName, acSaveNo
End Sub

Private Sub cmdOk_Click()
    If IsNull(lstCategory) Then
        MsgBox "Please select a value, or hit Cancel to Quit"
    Else
        Me.Visible = False
    End If
End Sub

What event can be guaranteed to fire whenever a Modal firm is opened.

Thanks,
Daniel



Sat, 10 Mar 2001 03:00:00 GMT  
 Modal Form: Form Load, Form Open, Form Activate events do not Fire
A method which will always deselect the listbox is as follows

Private Sub Form_Load()
    dim strRS as string
    with Me.lstCategory
        strRS = .RowSource
        .RowSource = ""
        .RowSource = strRS
    End With
End Sub

Quote:

>I wish for a user to clik on a text box (or hit the enter key on the text
>bok) and have a modal, dialog form open up that contains a listbox control.
>The user will select from the listbox, hit an OK button and return to the
>main form or Hit a cancel button and return to the main form.

>Everything works fine except that whenever I open the dialog form
>containing the listbox I want the listbox to be in an unselected state. The
>first time I open the dialog form this is the state, but every subsequent
>time the dialog form is opened the initial state of the listbox is selected
>with the choice made from the previous selection.

>Within the dialog form I have tried to code various events that would
>guarnatee that the listbox on the modal form is in an unselected state, all
>to no avail. Here is the code for the mainform text box that calls the
modal
>form.

>DoCmd.OpenForm "frmListCategory", , , , , acDialog   open as dialog
>    If SysCmd(acSysCmdGetObjectState, acForm, "frmListCategory") Then
>        'Form is still open
>        Me.txtCategoryName = Forms!frmListCategory!lstCategory.Column(1)
>        Me.txtCategoryId = Forms!frmListCategory!lstCategory.Column(0)
>        DoCmd.Close acForm, "frmListCategory", acSaveNo   I have set
>option for no save, but form retains settings
>    End If

>Note that I have closed the modal form with the DoCmd.Close actions.
>Nonetheless the next time the form is called, neither the Load, Open,
>Activate, or Get Focus events seems to be called. I have tried coding in
all
>these events

>Here is the code for the Modal form.

>Private Sub Form_Load()
>    Me.lstCategory.SetFocus
>    Me.lstCategory.Selected(0) = True
>    Me.lstCategory.Selected(0) = False
>End Sub

>Private Sub cmdCancel_Click()
>    DoCmd.Close acForm, Me.FormName, acSaveNo
>End Sub

>Private Sub cmdOk_Click()
>    If IsNull(lstCategory) Then
>        MsgBox "Please select a value, or hit Cancel to Quit"
>    Else
>        Me.Visible = False
>    End If
>End Sub

>What event can be guaranteed to fire whenever a Modal firm is opened.

>Thanks,
>Daniel



Sun, 11 Mar 2001 03:00:00 GMT  
 Modal Form: Form Load, Form Open, Form Activate events do not Fire

I am not sure I got it in the right place but what you want to do is set
the listbox to "" before you close it.

DoCmd.OpenForm "frmListCategory", , , , , acDialog  '' open as dialog
    If SysCmd(acSysCmdGetObjectState, acForm, "frmListCategory") Then
         'Form is still open
         Me.txtCategoryName = Forms!frmListCategory!lstCategory.Column(1)
         Me.txtCategoryId = Forms!frmListCategory!lstCategory.Column(0)
         'set listbox to blank
         Forms!frmListCategory!lstCategory = ""

        DoCmd.Close acForm, "frmListCategory", acSaveNo  '' I have set
 option for no save, but form retains settings
     End If



Quote:
> I wish for a user to clik on a text box (or hit the enter key on the text
> bok) and have a modal, dialog form open up that contains a listbox
control.
> The user will select from the listbox, hit an OK button and return to the
> main form or Hit a cancel button and return to the main form.

> Everything works fine except that whenever I open the dialog form
> containing the listbox I want the listbox to be in an unselected state.
The
> first time I open the dialog form this is the state, but every subsequent
> time the dialog form is opened the initial state of the listbox is
selected
> with the choice made from the previous selection.



Sun, 11 Mar 2001 03:00:00 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. Opening form 2 from form 1 - what form/event to close form 1

2. Events not firing when form is opend from another form

3. Modal Form property prevents firing of AfterDelConfirm event?

4. On activate event in modal pop up forms problem

5. Form Activate event for a pop up form

6. On Exit Event fires on loading of form

7. Modal: Need to stop VB while modal form loads

8. Activate Event happens before form loaded

9. Proper way to close a form in the Form Load event

10. Don't want Form Load event to trigger a Form Current procedure - Access2k


 
Powered by phpBB® Forum Software © phpBB Group