Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Combo box question

Status
Not open for further replies.

neerajam

Technical User
Mar 4, 2002
23
0
0
US
I have designed a database for my boss to keep track of his employees projects. For example this form contains a combo box for projects and the underlying table contains projectid, areaid, and projectdescription as fields. Right now I have pop-up forms being used to enter new data into the table. However, ideally I would like to add it to the combo box itself expecting the table to be updated. I know it involves the the not-in-list event but I am not sure how to proceed. Any help would be appreciated.

Thanks.
 
I use something like

Private Sub ComboName_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 " & vbCrLf & vbCrLf
strMsg = strMsg & "Do you want to associate the new Name to the current ?"
strMsg = strMsg & vbCrLf & vbCrLf & "Click Yes to add 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("tblOfComboSource", dbOpenDynaset)
On Error Resume Next
rs.AddNew
rs!NameOfRowInTable = 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 If
End Sub


Hope you can use it ...

Steve
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top