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!

OnNotInList Event (Not Working) 1

Status
Not open for further replies.

mommom

Technical User
Nov 14, 2003
208
0
0
US
I have put in the code listed below. However, Nothing is happening. It will not ask me if I want to add to the list or anything else. Can someone tell me what I did wrong?


Private Sub SSN_NotInList(NewData As String, Response As Integer)
'Suppress the default error message.
Response = acDataErrContinue
'Prompt user to verify they wish to add new value.
If MsgBox("The SSN is not in list. Add it?", vbYesNo) = vbYes Then
'Set Response argument to indicate that data is being added.
'Open a recordset of the SSN Table.
Dim db As Database
Dim rstSSN As Recordset
Dim sqlSSN As String
Set db = CurrentDb()
sqlSSN = "Select * From SSN"
Set rstSSN = db.OpenRecordset(sqlSSN, dbOpenDynaset)
'Add a new SSN with the value that is stored in the variable NewData.
rstSSN.AddNew
rstSSN![SSN] = NewData
rstSSN.Update
'Inform the combo box that the desired item has been added to the list.
Response = acDataErrAdded
rstSSN.Close 'Close the recordset

End If

End Sub
 
What is the value of the SSN.LimitToList property ?

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
The LimitToList is set to Yes.
 
How are ya mommom . . .

Try this:
Code:
[blue]   Dim db As DAO.Recordset, rst As DAO.Recordset, SQL As String
    
   If MsgBox("The SSN is not in list.  Add it?", vbYesNo) = vbYes Then
      Set db = CurrentDb()
      SQL = "Select * From SSN"
      Set rst = db.OpenRecordset(SQL, dbOpenDynaset)
      rst.AddNew
      rst![SSN] = NewData
      rst.Update
      Set rst = Nothing
      Response = acDataErrAdded
   Else
    Response = acDataErrContinue
   End If[/blue]

Calvin.gif
See Ya! . . . . . .
 
mommom . . .

Hit submit too soon. Should be:
Code:
[blue]   Dim db As DAO.Recordset, rst As DAO.Recordset, SQL As String
    
   If MsgBox("The SSN is not in list.  Add it?", vbYesNo) = vbYes Then
      Set db = CurrentDb()
      SQL = "Select * From SSN"
      Set rst = db.OpenRecordset(SQL, dbOpenDynaset)
      rst.AddNew
      rst![SSN] = NewData
      rst.Update
      Set rst = Nothing
      Response = acDataErrAdded
   Else
      [purple]Me.Undo[/purple]
      Response = acDataErrContinue
   End If[/blue]

Calvin.gif
See Ya! . . . . . .
 
Hello AceMan1,

I changed it, but it still doesn't work. What happens is I put in the new SSN but for some reason when I hit either tab or enter key it goes blank.

Not sure why that is happening.
 
What I am getting now is Run-time error '13':

Type mismatch
 
Forgot to add where the error is coming from:

Set db = CurrentDb()
 
Forgot to add where the error is coming from:

Set db = CurrentDb()
 
Replace this:
Dim db As DAO.Recordset
with this:
Dim db As DAO.Database

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
The change worked, it does go into the list. However, now once it you click yes add to list it automatically goes to a new record instead of allowing me to continue to work on the same page. Do you know what can be causing this??
 
mommom . . .

Is the combobox the last field in the [blue]Tab Order[/blue] ([blue]MenuBar - View - Tab Order[/blue])?

Calvin.gif
See Ya! . . . . . .
 
Thanks AceMan - that did it.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top