Adding Item to ComboBox using NotInList

S

Sheldon

Hi,

I'm using the following code to add and item to a combo
box with Not In List. I get an error "Block If without
End If. Please help.

Private Sub Rec_dByName_NotInList(NewData As String,
Response As Integer)
Dim db As DAO.Database
Dim rs As DAO.Recordset
Dim strMsg As String

strMsg = "'" & NewData & "' is not an available User
Name " & vbCrLf & vbCrLf
strMsg = strMsg & "Do you want to associate the new
Name to the current DLSAF?"
strMsg = strMsg & vbCrLf & vbCrLf & "Click Yes to link
or No to re-type it."

If MsgBox(strMsg, vbQuestion + vbYesNo, "Add new
name?") = vbNo Then
Response = acDataErrContinue
Else
Set db = CurrentDb
Set rs = db.OpenRecordset("tblUsers",
dbOpenDynaset)
On Error Resume Next
rs.AddNew
rs!UserName = NewData
rs.Update

If Err Then
MsgBox "An error occurred. Please try again."
Response = acDataErrContinue
Else
Response = acDataErrAdded
End If

rs.Close
Set rs = Nothing
Set db = Nothing

End Sub
 
G

Gary Miller

Sheldon,

Count your Ifs and End Ifs. You have 2 Ifs and only one End
If. Looks the 'If MsgBox' line is the one missing the
closing End IF and maybe it should go here...

rs.Update
End If
If Err Then


--

Gary Miller
Gary Miller Computer Services
Sisters, OR
________________________
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top