add record in combo

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
 
N

Naresh Nichani

Hi:

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

Regards,

Naresh Nichani
Microsoft Access MVP
 
I

Ivica Lopar

LResponse = MsgBox(NewData & " ni v seznamu. Ali ga zeliz dodati v
Sintax eror in this line
 
D

Douglas J Steele

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?
 
I

Ivica Lopar

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
 
D

Douglas J. Steele

You could try doing a Requery on the combo, although I wouldn't have thought
it was necessary.
 

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