J
justme
I have a form based on one table. On it, I have a combo box with not_in_list
sub to add the new style number. The combo box requeries ok, but the form
does not and can't find the new number in a search.
I have tried
Me.Requery
Me.Refresh
in combinations with Me.dirty = False or If me.Dirty = True then me.dirty =
false
I tried placing various combinations in several places, such as
in the sub right after the new data is inserted into the table
at the end of the sub
putting in its own sub and calling it.
Any time I place the requery/refresh command in the code ANYWHERE, it messes
up the combo box requery, and then nothing is requeried.
I even put a requery command button using the wizard, and put a msgBox in
the sub. The msgBox comes up, but I still can not find the style in the
form, even though it shows in my combo box drop down. the only way I can get
the form to see it is to close & re-open it.
Do you have any suggestions? I have been searching & trying posts for more
than 2 hours now.
Thanks.
Private Sub cboFindStyle_NotInList(NewData As String, Response As Integer)
'------------------------------------------------------------
' To add New Style - direct insert into tFits
'------------------------------------------------------------
Dim Db As DAO.Database
Dim rs1 As DAO.Recordset
Dim rs2 As Object
Dim strMsg1 As String
Dim Result
Dim strMsg2 As String
Dim sqlAddStyle As String
On Error GoTo ErrorHandler
' Exit this subroutine if the combo box was cleared.
If NewData = "" Then Exit Sub
' Confirm that the user wants to add the new StyleNumber.
strMsg1 = " '" & UCase(NewData) & "'" & NL & NL _
& "is not a known StyleNumber. " & NL _
& " Would you like to add it?" & NL & NL & NL _
& " Click No to re-type it" & NL
If MsgBox(strMsg1, vbQuestion + vbYesNo) = vbNo Then
' If the user chooses not to add a StyleNumber, set the Response
' argument to suppress an error message and undo changes.
Response = acDataErrContinue
' Display a customized message.
Me.Undo
MsgBox NL & NL & " Please re-enter a StyleNumber " &
NL & NL _
& " or press ESC" & NL & NL & NL
Me.cboFindStyle = Me.StyleID
Else
strMsg2 = NL & NL & " Are you sure you wish to add
" & NL & NL _
& " " & Me.cboFindStyle.text & " ?" & NL & NL
& NL
' If the user chose to add a new StyleNumber, open a recordset
' using the tFits table.
If MsgBox(strMsg2, vbQuestion + vbYesNo) = vbNo Then
Response = acDataErrContinue
' If the user chose not to add a StyleNumber, set the Response
' argument to suppress an error message and undo changes.
' Display a customized message.
Me.Undo
MsgBox NL & NL & " Please re-enter the StyleNumber
" & NL & NL _
& " or press ESC" & NL & NL & NL
Me.cboFindStyle = Me.StyleID
Else
sqlAddStyle = "Insert Into tFits ([StyleID]) values ('" &
UCase(NewData) & "')"
CurrentDb.Execute sqlAddStyle, dbFailOnError
Response = acDataErrAdded
' Look for the StyleNumber the user created in the BuyerAdd form.
Result = DLookup("[StyleID]", "tFits", "[StyleID] ='" & NewData
& "'")
If IsNull(Result) Then
' If the StyleNumber was not created, set the Response
argument
' to suppress an error message and undo changes.
Response = acDataErrContinue
Me.Undo
'Me.Requery
Me.Dirty = False
MsgBox NL & NL & " The StyleNumber was NOT Added." & NL &
NL _
& " Please re-type the StyleNumber or press ESC" &
NL & NL & NL, vbInformation
Response = acDataErrAdded
Else
If Not IsNull(Result) Then
' If the StyleNumber was created, set the Response argument to
' indicate that new data is being added.
Response = acDataErrAdded
End If
End If
End If
End If
ExitHandler:
Exit Sub
ErrorHandler:
' An unexpected error occurred, display the normal error message.
MsgBox Err.Description
' Set the Response argument to suppress an error message and undo
' changes.
Response = acDataErrContinue
End Sub
sub to add the new style number. The combo box requeries ok, but the form
does not and can't find the new number in a search.
I have tried
Me.Requery
Me.Refresh
in combinations with Me.dirty = False or If me.Dirty = True then me.dirty =
false
I tried placing various combinations in several places, such as
in the sub right after the new data is inserted into the table
at the end of the sub
putting in its own sub and calling it.
Any time I place the requery/refresh command in the code ANYWHERE, it messes
up the combo box requery, and then nothing is requeried.
I even put a requery command button using the wizard, and put a msgBox in
the sub. The msgBox comes up, but I still can not find the style in the
form, even though it shows in my combo box drop down. the only way I can get
the form to see it is to close & re-open it.
Do you have any suggestions? I have been searching & trying posts for more
than 2 hours now.
Thanks.
Private Sub cboFindStyle_NotInList(NewData As String, Response As Integer)
'------------------------------------------------------------
' To add New Style - direct insert into tFits
'------------------------------------------------------------
Dim Db As DAO.Database
Dim rs1 As DAO.Recordset
Dim rs2 As Object
Dim strMsg1 As String
Dim Result
Dim strMsg2 As String
Dim sqlAddStyle As String
On Error GoTo ErrorHandler
' Exit this subroutine if the combo box was cleared.
If NewData = "" Then Exit Sub
' Confirm that the user wants to add the new StyleNumber.
strMsg1 = " '" & UCase(NewData) & "'" & NL & NL _
& "is not a known StyleNumber. " & NL _
& " Would you like to add it?" & NL & NL & NL _
& " Click No to re-type it" & NL
If MsgBox(strMsg1, vbQuestion + vbYesNo) = vbNo Then
' If the user chooses not to add a StyleNumber, set the Response
' argument to suppress an error message and undo changes.
Response = acDataErrContinue
' Display a customized message.
Me.Undo
MsgBox NL & NL & " Please re-enter a StyleNumber " &
NL & NL _
& " or press ESC" & NL & NL & NL
Me.cboFindStyle = Me.StyleID
Else
strMsg2 = NL & NL & " Are you sure you wish to add
" & NL & NL _
& " " & Me.cboFindStyle.text & " ?" & NL & NL
& NL
' If the user chose to add a new StyleNumber, open a recordset
' using the tFits table.
If MsgBox(strMsg2, vbQuestion + vbYesNo) = vbNo Then
Response = acDataErrContinue
' If the user chose not to add a StyleNumber, set the Response
' argument to suppress an error message and undo changes.
' Display a customized message.
Me.Undo
MsgBox NL & NL & " Please re-enter the StyleNumber
" & NL & NL _
& " or press ESC" & NL & NL & NL
Me.cboFindStyle = Me.StyleID
Else
sqlAddStyle = "Insert Into tFits ([StyleID]) values ('" &
UCase(NewData) & "')"
CurrentDb.Execute sqlAddStyle, dbFailOnError
Response = acDataErrAdded
' Look for the StyleNumber the user created in the BuyerAdd form.
Result = DLookup("[StyleID]", "tFits", "[StyleID] ='" & NewData
& "'")
If IsNull(Result) Then
' If the StyleNumber was not created, set the Response
argument
' to suppress an error message and undo changes.
Response = acDataErrContinue
Me.Undo
'Me.Requery
Me.Dirty = False
MsgBox NL & NL & " The StyleNumber was NOT Added." & NL &
NL _
& " Please re-type the StyleNumber or press ESC" &
NL & NL & NL, vbInformation
Response = acDataErrAdded
Else
If Not IsNull(Result) Then
' If the StyleNumber was created, set the Response argument to
' indicate that new data is being added.
Response = acDataErrAdded
End If
End If
End If
End If
ExitHandler:
Exit Sub
ErrorHandler:
' An unexpected error occurred, display the normal error message.
MsgBox Err.Description
' Set the Response argument to suppress an error message and undo
' changes.
Response = acDataErrContinue
End Sub