Adding a new entry to a CBO

  • Thread starter Thread starter Doug
  • Start date Start date
D

Doug

I would like to be able to add new entries to a cbo
(ASECContact) and I have used the statement below. I have
used this same statement on other databases and it works
fine. But this time Access is not liking the DIM
statement? Any advice appreciated
thanks


Private Sub Combo137_NotInList(NewData As String,
Response As Integer)
Dim db As Database
Set db = CurrentDb

'Ask the user if they want to add to the list
If MsgBox("Do you want to add this entity to the list?",
vbYesNo + vbQuestion, "Add new value?") = vbYes Then

'The user clicked Yes - add the new value
db.Execute "INSERT INTO tblASECContact (ASECContact)
VALUES (""" & NewData & """)", dbFailOnError

'Tell Access you've added the new value
Response = acDataErrAdded

Else

'The user clicked No - discard the new value
Me.Combo137.Undo
'Tell Access you've discarded the new value
Response = acDataErrContinue

End If

db.Close
Set db = Nothing
End Sub
 
Open the code window and select the tools/references from the main menu.
Make sure Microsoft DAO 3.6 Object Library has a check mark and it doesn't
say (Missing) next to it. Also, if Microsoft ActiveX Data Objects 2.1
Library is selected, Move the DAO library above it using the priorities
buttons on the form. I would also recommend exclusive calling out the DAO
library like so

Dim db As DAO.Database

Hope this helps!
 
Thanks Reggie, works a breeze.
-----Original Message-----
Open the code window and select the tools/references from the main menu.
Make sure Microsoft DAO 3.6 Object Library has a check mark and it doesn't
say (Missing) next to it. Also, if Microsoft ActiveX Data Objects 2.1
Library is selected, Move the DAO library above it using the priorities
buttons on the form. I would also recommend exclusive calling out the DAO
library like so

Dim db As DAO.Database

Hope this helps!

--
Reggie

----------



.
 
Back
Top