Not in list

M

myxmaster

Hello,
I am using the following code in a combobox named authorizers. When I
enter a new name I get a message telling me an error occured. Any help
is most appreciated.

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 Authorizer_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 a authorized Name " & vbCrLf &
vbCrLf
strMsg = strMsg & "Do you want to add the new Name to the current
List?"
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("Authorizer", 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
 
M

myxmaster

Hi Wayne,
I made the change however it still won't work. The table tame is
Authorizers and the field name is Authorizer.
 
M

myxmaster

Hi Wayne,
I made the change however it still won't work. The table tame is
Authorizers and the field name is Authorizer.
 
W

Wayne-I-M

No worries - try this

Private Sub Authorizer _NotInList(NewData As String, Response As Integer)
Dim Db As DAO.Database
Dim rs As DAO.Recordset
Dim Msg As String
Msg = "'" & NewData & "' is not a authorized Name ." & vbCr & vbCr
Msg = Msg & "Do you want to add a new name to the current list?"
If MsgBox(Msg, vbQuestion + vbYesNo) = vbNo Then
Response = acDataErrContinue
MsgBox "Try again."
Else
Set Db = CurrentDb
Set rs = Db.OpenRecordset("Authorizers ", dbOpenDynaset)
rs.AddNew
rs![ AEName] = NewData
rs.Update
Response = acDataErrAdded
End If
End Sub


Notes
The table name being search/added to is called Authorizers
The combobox name is named Authorizer
The field being searched by combo Authorizer is AEName

Hope this helps - going out now for lunch - I need it
 
M

myxmaster

No worries - try this

Private Sub Authorizer _NotInList(NewData As String, Response As Integer)
Dim Db As DAO.Database
Dim rs As DAO.Recordset
Dim Msg As String
Msg = "'" & NewData & "' is not a authorized Name ." & vbCr & vbCr
Msg = Msg & "Do you want to add a new name to the current list?"
If MsgBox(Msg, vbQuestion + vbYesNo) = vbNo Then
Response = acDataErrContinue
MsgBox "Try again."
Else
Set Db = CurrentDb
Set rs = Db.OpenRecordset("Authorizers ", dbOpenDynaset)
rs.AddNew
rs![ AEName] = NewData
rs.Update
Response = acDataErrAdded
End If
End Sub

Notes
The table name being search/added to is called Authorizers
The combobox name is named Authorizer
The field being searched by combo Authorizer is AEName

Hope this helps - going out now for lunch - I need it

--
Wayne
Manchester, England.



Hi Wayne,
I made the change however it still won't work. The table tame is
Authorizers and the field name is Authorizer.

- Show quoted text -

Hi Wayne,
The routine staps at
rs!AEName = NewData
Any ideas
TIA
 
S

storrboy

Hi Wayne,
The routine staps at
rs!AEName = NewData
Any ideas
TIA


If I may interject...

Change the line
MsgBox "An error occurred. Please try again."

To
MsgBox "An error occurred. Please try again.", vbOkOnly, "Error# "
& Err.Number

and try running it again. This will indicate the actual error
encountered and help others to diagnose.
 
D

Douglas J. Steele

Error 3265 is "Item not found in this collection." The implication to me is
that AEName doesn't exist in the recordset: that it's called something else.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top