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

ComboBox: NotInList event "firing" twice...

Status
Not open for further replies.

4N6Mstr

Technical User
Oct 6, 2008
40
US
Hello, all!

On an Access 2007 db (accdb) I have a split form (popup = no, modal = yes) that shows only the header and the datasheet portion (detail.visible = no). On the header portion, I have an unbound combobox, a textbox and two buttons 1) Tag and 2) Cancel.
The intended functionality is:

A) For existing tags (no problem with this part)

1) The user picks a tag from the combobox list
2) The text box receives the correspondent description for that tag
3) The user than clicks Tag to tag the records displayed on the datasheet portion (which were previously chosen on another form. The routine to tag the forms is not included below)
3a) or The user changes his / her mind and click Cancel, the records are not tagged and the form is closed.


B) If the user enters a value that is not in list for the combo

1) The NotInList events fires up
2) A new form is displayed (Popup = yes, modal = yes, Cycle = current record, Data Entry = Yes, Allow Additions = Yes, acformadd, acdialog, OpenArgs = NewData). The for has two text boxes and a two buttons.
3) After being opened, one of the form’s text boxes value is set to OpenArgs (NewData) and the focus is moved to the other text box so the user can enter the description
4) After the description input, the user should select Confirm , to create a new tag (THE PROBLEM HAPPENS HERE)
4a)or Cancel if the user changes his / her mind.

All should be pretty simple; however, when the user selects the Confirm button the NotInList event on the other form is activated again!!!!! I mean, instead of returning to the previous form code immediately after the OpenForm command, which I though it would be the case using acDialog. Therefore, the user receives the “Not in list, add it” message again, and the application tries to open the data entry form again, etc.

Naturally, this is not the expected behavior.

I bet is something stupid, but I can’t see it. Suggestions?

The code is below.

Form 1)
Private Sub cbx_TagDescription_NotInList(NewData As String, Response As Integer)
On Error GoTo Err_cbx_TagDescription_NotInList

Dim strSQL As String
Dim rstTagsDescriptions As ADODB.Recordset
Dim cnnTableConnection As ADODB.Connection
Dim intTagTooLong As Integer

If MsgBox("Value is not in list. Add it?", _
vbOKCancel) = vbOK Then
DoCmd.OpenForm "frm_Tag_Observation_DataEntry", , , , DataMode:=acFormAdd, windowmode:=acDialog, OpenArgs:=NewData
intTagTooLong = MsgBox("Control Again on combo", vbCritical)
If Not IsNull(cbx_TagDescription.Value) Then
'If User confirmed the new data entry on form "frm_TagsObservations_DataEntry"
'then changes to "cbx_TagDescription" source should be confirmed
Response = acDataErrAdded
Me.txt_AccountComment.SetFocus
Else
'If User canceled the new data entry on form "frm_TagsObservations_DataEntry"
'then changes to "cbx_TagDescription" were canceled (undo)
'With changes to the combo box source canceled then the warning of "not in list" is to be supressed
Response = acDataErrContinue
End If
Else
Response = acDataErrContinue 'cancel changes to combo box source
Me.cbx_TagDescription.Undo
End If

Exit_cbx_TagDescription_NotInList:
Exit Sub

Err_cbx_TagDescription_NotInList:
MsgBox Err.Description
Resume Exit_cbx_TagDescription_NotInList

End Sub



Form 2)

Private Sub Form_Load()
On Error GoTo Err_Form_Load

If Me.DataEntry And Not (IsNull(Me.OpenArgs)) Then
Me.txt_TagDescription = Me.OpenArgs
End If

Me.txt_Observation.SetFocus

Exit_Form_Load:
Exit Sub

Err_Form_Load:
MsgBox Err.Description
Resume Exit_Form_Load

End Sub

Private Sub cmd_Confirm_Click()
Dim intObservationIsEmpty As Integer

If IsNull(Me.txt_Observation) Or Len(Me.txt_Observation) < 1 Then
intObservationIsEmpty = MsgBox("Please complete Observation for Tag before Confirming or Cancel!", vbCritical, "Observation is empty!!!")
Me.txt_Observation.SetFocus
Else
Me.Dirty = False (HERE IS WHERE THE "NotInList" EVENT IS FIRED AGAIN)

DoCmd.Close
End If
End Sub

Private Sub cmd_Cancel_Click()
On Error GoTo Err_cmd_Cancel_Click

Me.Undo
Me.Dirty = False
Forms!frm_Tag_Observation_Selection.Form![cbx_TagDescription].Undo
DoCmd.Close

Exit_cmd_Cancel_Click:
Exit Sub

Err_cmd_Cancel_Click:
MsgBox Err.Description
Resume Exit_cmd_Cancel_Click

End Sub



Any help is always apreciated!

Thx,


4N6MSTR
______________________________________________
If you don't know where you are going
It does not matter how fast you are
You will never get there
 
Why are you setting the dirty property to false?
My guess is that you want to save the record here.
Assuming I am remembering the constant right cold...

Code:
docmd.runcommand acCmdSaveRecord

Even so, I am not sure that solves your problem... You may need to Requery the combobox on form1 after creating and saving the record.
 
Lameid,

Thank you for your post.

I did find my errors:

1) I was trying to move the focus away from the combo box before the Notinlist event was complete. Even though I was setting the correct Response (acDayaErrAdded) The combo box "records" wete not updayed at that point, which generated the second NotInList.

2) I was using .value to test for user cancelation of the addition of the tag (I undo the combo box in that situation). However; the value is not set yet in NotInList, just the .text (although that was not the cause of the extra NotInList)

Cheers!

Any help is always apreciated!

Thx,


4N6MSTR
______________________________________________
If you don't know where you are going
It does not matter how fast you are
You will never get there
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top