Alex.Wisnoski@ncmail.net (Alex Wisnoski) wrote in message news:<5c7e7e3c.0312041228.5d3ff3fa@posting.google. com>...[color=blue]
> Access 97SR2-I am trying to create a Job Position data entry form
> based on a table. The form has 15 fields on it. I want to use a
> combo box to look in the table and see if the position number already
> exists. If the position exists, then pull up that record and display
> the information on the form. If the position doesn't exist, inform
> the user and ask if they want to add it. If they elect to add it,
> then have a new record to add it in to. My form has Save, Delete,
> Clear, and Close buttons. I have tried having my combo box both bound
> and unbound but have not been able to get everything to work yet.[/color]
Try this:
Private Sub Reason_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 AE 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("tblReasons", dbOpenDynaset)
On Error Resume Next
rs.AddNew
rs!Reason = NewData
rs.Update
If Err Then
MsgBox "An error occurred. Please try again."
Response = acDataErrContinue
Else
Response = acDataErrAdded
End If
End If
rs.Close
Set rs = Nothing
End Sub
'************ Code Start **********
' This code was originally written by Dev Ashish. ' It is not to be
altered or distributed,' except as part of an application. ' You are
free to use it in any application, ' provided the copyright notice is
left unchanged.'' Code Courtesy of ' Dev Ashish'
Private Sub cbxAEName_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 AE 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("tblAE", dbOpenDynaset)
On Error Resume Next
rs.AddNew
rs!AEName = NewData
rs.Update
If Err Then
MsgBox "An error occurred. Please try again."
Response = acDataErrContinue
Else
Response = acDataErrAdded
End If
End If
rs.Close
Set rs = Nothing
Set db = Nothing
End Sub
'*********** Code End **************
from
www.mvps.org/Access