CBO Box not updating w/code

Teknq2000

New member
Local time
Today, 15:07
Joined
Dec 24, 2006
Messages
3
I have this code to update my combo list when NewData is entered. NewData is not updating in the cbo box. I am new and still learning. Please help.

Private Sub POC_NotInList(NewData As String, Response As Integer)
On Error GoTo cboPOC_NotInList_Err
Dim intAnswer As Integer
Dim strSQL As String
intAnswer = MsgBox("POC " & Chr(34) & NewData & _
Chr(34) & " is not currently listed." & vbCrLf & _
"Would you like to add it to the list now?" _
, vbQuestion + vbYesNo, " POC")
If intAnswer = vbYes Then
strSQL = "INSERT INTO MARK20A([POC]) " & _
"VALUES ('" & NewData & "');"
DoCmd.SetWarnings False
DoCmd.RunSQL strSQL
MsgBox "The new POC has been added to the list." _
, vbInformation, "POC "
Response = acDataErrAdded
Else
MsgBox "Please choose a POC from the list." _
, vbInformation, " "
Response = acDataErrContinue
End If
 
Combo box not updating w/code

I get the MS message "Select an item from the list or enter text that matches one of the listed items"
 
You never requery the combo box to refresh it. Therefore, the change won't appear there. The format is like this (I didn't see the name of your combo box, so adjust this as necessary):

YourComboBoxName.Requery

Place that at the end of the code after you've updated the recordset.

Additionally, you can really clean up that code by getting rid of the variables and using an Execute instead of a RunSQL. Execute will not invoke warning messages, so there's no need to SetWarnings Off or On. Cleaned up, it's clearer to read as well, like this:
Code:
Private Sub POC_NotInList(NewData As String, Response As Integer)

    On Error GoTo cboPOC_NotInList_Err ' <--- Where is this going?
	
    If MsgBox("POC " & Chr(34) & NewData & Chr(34) & " is not currently listed." & vbCrLf & _
        "Would you like to add it to the list now?", vbQuestion + vbYesNo, "POC") = vbYes Then
	CurrentDb.Execute "INSERT INTO MARK20A([POC]) VALUES ('" & NewData & "');"
        MsgBox "The new POC has been added to the list.", vbInformation, "POC"   
        Response = acDataErrAdded
    Else
        MsgBox "Please choose a POC from the list.", vbInformation, ""
	Response = acDataErrContinue
    End If

End Sub

It just makes the code easier to debug and maintain (for you), and easier to debug for us when you post it. ;)

~Moniker
 
thanks Moniker that really helped. Learned a lesson or two today. Merry Christmas!
 

Users who are viewing this thread

Back
Top Bottom