Combo box (feild and list) (1 Viewer)

T

T-Bone

Guest
Hi This is the first time I have tried one of there forums so please bear with me. I have writen some databases in lotus approach. I have had many people tell me how much better Access is and so am trying to learn it. What I want to do is create a feild where a user can type in a name if that name is in the table already it will complet it as they type if it is not it is added to the table when they tab out of the feild so next time that name is typed it will auto complet. the problem I have is that one way only the names I manualy enter into the table auto complet and the others are not added or every name is added each time it is entered and so I end up with the same name over and over again. Thank you in advance for any help give.
T-Bone
 

wh00t

Registered User.
Local time
Today, 01:50
Joined
May 18, 2001
Messages
264
Try this

Private Sub Froma_NotInList(NewData As String, Response As Integer)
Dim Db As Database
Dim Rs As Recordset
Dim Msg As String
Dim CR As String

CR = Chr$(13)

If NewData = "" Then Exit Sub
Set Db = CurrentDb
Set Rs = Db.OpenRecordset("Table Name", DB_OPEN_TABLE)
On Error Resume Next
Rs.AddNew

Rs![Field Name] = NewData
' Save the record.
Rs.Update

If Err Then
' If a run-time error occurred while attempting to add a new
' record, set the Response argument to suppress an error
' message and undo changes.
Response = acDataErrContinue
' Display a customized message.
MsgBox Error$ & CR & CR & "Please try again.", vbExclamation
Else
' If a run-time error did not occur, set Response argument
' to indicate that new data is being added.
Response = acDataErrAdded
End If


End Sub


should work

[This message has been edited by wh00t (edited 05-18-2001).]
 

Users who are viewing this thread

Top Bottom