G
gin
Hi List:
I've always had issues with NotInList, but today is just really the
kicker. Would someone help me to see what I'm missing?
Here's the code from a combobox that runs fine, updates the table &
~poof~ unexpectedly closes the form. It closes the form whether I
straight insert using the SQL insert function I wrote, or when I call
a popup & have the user insert the record.
The really interesting part is that the form is NOT closed when I step
through the NotInList event & I don't see anything (see below) that
looks like it *should* close the form. This NotInList event runs
flawlessly from another form. This led me to check and compare the
BAD form's properties, but I don't see a difference. It seems like it
has something to do with the form itself, and not the combo box (I
copied a combo from a "good" form where I know it runs OK & form close
behavior persisted). Checking the code on form's events, I didn't
really see anything I thought might cause this behavior.
Any clues or tips?
Many thanks in advance,
'--------------------------code
start--------------------------------------
Private Sub cboFWP_NotInList(NewData As String, Response As Integer)
On Error GoTo Errorhandler
NewData = Trim(NewData)
If MsgBox("FWP '" & NewData & "' is not in the " & _
"List." & vbCrLf & vbCrLf & _
"Would you like to add it?" & vbCrLf & vbCrLf & _
"Click Yes to Add. " & vbCrLf & _
"Click No to undo this entry, then select an existing FWP
from the list to continue.", _
vbYesNo + vbQuestion, "Add FWP to List?") = vbYes Then
If SimpleInsertSQL("FWP", "FWP_NO", NewData) = True Then
Response = acDataErrAdded
Else
MsgBox "Error Adding FWP to list.", vbCritical
End If
Else
Me.cboFWP.Undo
Response = acDataErrContinue
End If
Exit_Errorhandler:
Exit Sub
Errorhandler:
MsgBox Err.Description
Resume Exit_Errorhandler
End Sub
Public Function SimpleInsertSQL(Tablename As String, FldName As
String, value As String) As Boolean
DoCmd.SetWarnings False
strSQL = "INSERT INTO " & Tablename & " (" & FldName & ") " & _
"Values ('" & value & "')"
'Debug.Print strSQL
DoCmd.RunSQL strSQL
If Err.Number > 0 Then
SimpleInsertSQL = False
Else
SimpleInsertSQL = True
End If
DoCmd.SetWarnings True
End Function
'--------------------------code
end--------------------------------------
I've always had issues with NotInList, but today is just really the
kicker. Would someone help me to see what I'm missing?
Here's the code from a combobox that runs fine, updates the table &
~poof~ unexpectedly closes the form. It closes the form whether I
straight insert using the SQL insert function I wrote, or when I call
a popup & have the user insert the record.
The really interesting part is that the form is NOT closed when I step
through the NotInList event & I don't see anything (see below) that
looks like it *should* close the form. This NotInList event runs
flawlessly from another form. This led me to check and compare the
BAD form's properties, but I don't see a difference. It seems like it
has something to do with the form itself, and not the combo box (I
copied a combo from a "good" form where I know it runs OK & form close
behavior persisted). Checking the code on form's events, I didn't
really see anything I thought might cause this behavior.
Any clues or tips?
Many thanks in advance,
'--------------------------code
start--------------------------------------
Private Sub cboFWP_NotInList(NewData As String, Response As Integer)
On Error GoTo Errorhandler
NewData = Trim(NewData)
If MsgBox("FWP '" & NewData & "' is not in the " & _
"List." & vbCrLf & vbCrLf & _
"Would you like to add it?" & vbCrLf & vbCrLf & _
"Click Yes to Add. " & vbCrLf & _
"Click No to undo this entry, then select an existing FWP
from the list to continue.", _
vbYesNo + vbQuestion, "Add FWP to List?") = vbYes Then
If SimpleInsertSQL("FWP", "FWP_NO", NewData) = True Then
Response = acDataErrAdded
Else
MsgBox "Error Adding FWP to list.", vbCritical
End If
Else
Me.cboFWP.Undo
Response = acDataErrContinue
End If
Exit_Errorhandler:
Exit Sub
Errorhandler:
MsgBox Err.Description
Resume Exit_Errorhandler
End Sub
Public Function SimpleInsertSQL(Tablename As String, FldName As
String, value As String) As Boolean
DoCmd.SetWarnings False
strSQL = "INSERT INTO " & Tablename & " (" & FldName & ") " & _
"Values ('" & value & "')"
'Debug.Print strSQL
DoCmd.RunSQL strSQL
If Err.Number > 0 Then
SimpleInsertSQL = False
Else
SimpleInsertSQL = True
End If
DoCmd.SetWarnings True
End Function
'--------------------------code
end--------------------------------------