add record in combo

  • Thread starter Thread starter Ivica Lopar
  • Start date Start date
I

Ivica Lopar

I have error in this code.Help please.

regards
lopar


Private Sub Task_NotInList(NewData As String, Response As Integer)

Dim db As Database

Dim LSQL As String
Dim LResponse As Integer
Dim ctl As Control

On Error GoTo Err_Execute

'Category combo box control
Set ctl = Me!Task

LResponse = MsgBox(NewData & " ni v seznamu. Ali ga zeliz dodati v
seznam?", vbYesNo, "Add Item")

'User responded "Yes" to adding the new item to the combo box
If LResponse = vbYes Then
Set db = CurrentDb()

'Insert new item into underlying table
LSQL = "insert into Tasks (Task) values ('" & NewData & "')"

db.Execute LSQL, dbFailOnError

Set db = Nothing

'Set Response argument to indicate that data is being added.
Response = acDataErrAdded

Else
'Set Response argument to suppress error message and undo changes
Response = acDataErrContinue
ctl.Undo
End If

On Error GoTo 0

Exit Sub

Err_Execute:
ctl.Undo
MsgBox "Action failed"

End Sub
 
Hi:

Your code looks good. I would remove the ctl.Undo and try and see what
happens.

Regards,

Naresh Nichani
Microsoft Access MVP
 
LResponse = MsgBox(NewData & " ni v seznamu. Ali ga zeliz dodati v
Sintax eror in this line
 
Assuming that's entered as a single line in your code, there's nothing
syntactically incorrect about it.

Does the error occur when you try to compile the code, or only when you run
it?
 
It is working now but new record is on the combo box list after I get out of
database.I wont if is posibble that I have item on list immediately after I
add new record .
----- Original Message -----
From: "Douglas J Steele" <NOSPAM_djsteele@NOSPAM_canada.com>
Newsgroups: microsoft.public.access.modulesdaovba
Sent: Wednesday, January 04, 2006 6:45 PM
Subject: Re: add record in combo
 
You could try doing a Requery on the combo, although I wouldn't have thought
it was necessary.
 
Back
Top