473,503 Members | 1,727 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Help with Insert statment

Hi Yall...

This is my objective:

I want the following snip of code to insert 2 values into table
'Failures'. The first value is based on a string that a user would
type into a combo box. If the value is not in the list, the 'Not in
List' procedure runs...That's where I've placed my code. The second
value must be extracted from a control that resides on the same form
'frmMain'. I can get everything to work if I enter a constant into the
second value of the Insert Statement (it is currently a '36'). The
value that I want in there is from a text box called txtEquipIDHolder.
I have tried everything I know to get that to work but I'm stuck...
Private Sub cboFailures_NotInList(NewData As String, Response As
Integer)
Dim db As Database

Dim LSQL As String
Dim LResponse As Integer
Dim ctl As Control
Dim ctlEquip As Control
On Error GoTo Err_Execute

'Category combo box control
Set ctl = Me!cboFailures
Set ctlEquip = Me!txtEquipIDHolder

LResponse = msgBox(NewData & " is a new item. Do you wish to add
it to the combo box?", vbYesNo, "Add Item")
'Debug msgBox (txtEquip & " works!!!")

'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 Failures (FailureName,EquipmentID) values
('" & NewData & "','36')"
db.Execute LSQL, dbFailOnError
'show new Value
Me.cboFailures = Null
Me.cboFailures.Requery
Me.cboFailures = Me.cboFailures.ItemData(0)

'Reset Database
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

Jan 8 '07 #1
2 1360

Grub wrote:
Hi Yall...

This is my objective:

I want the following snip of code to insert 2 values into table
'Failures'. The first value is based on a string that a user would
type into a combo box. If the value is not in the list, the 'Not in
List' procedure runs...That's where I've placed my code. The second
value must be extracted from a control that resides on the same form
'frmMain'. I can get everything to work if I enter a constant into the
second value of the Insert Statement (it is currently a '36'). The
value that I want in there is from a text box called txtEquipIDHolder.
I have tried everything I know to get that to work but I'm stuck...
Private Sub cboFailures_NotInList(NewData As String, Response As
Integer)
Dim db As Database

Dim LSQL As String
Dim LResponse As Integer
Dim ctl As Control
Dim ctlEquip As Control
On Error GoTo Err_Execute

'Category combo box control
Set ctl = Me!cboFailures
Set ctlEquip = Me!txtEquipIDHolder

LResponse = msgBox(NewData & " is a new item. Do you wish to add
it to the combo box?", vbYesNo, "Add Item")
'Debug msgBox (txtEquip & " works!!!")

'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 Failures (FailureName,EquipmentID) values
('" & NewData & "','36')"
db.Execute LSQL, dbFailOnError
'show new Value
Me.cboFailures = Null
Me.cboFailures.Requery
Me.cboFailures = Me.cboFailures.ItemData(0)

'Reset Database
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
Try LSQL = "insert into Failures (FailureName,EquipmentID) values
('" & NewData & "','" & txtEquipIDHolder & "')"

Bruce

Jan 8 '07 #2
Brilliant, worked as advertised...Thanks Bruce!
de***************@gmail.com wrote:
Grub wrote:
Hi Yall...

This is my objective:

I want the following snip of code to insert 2 values into table
'Failures'. The first value is based on a string that a user would
type into a combo box. If the value is not in the list, the 'Not in
List' procedure runs...That's where I've placed my code. The second
value must be extracted from a control that resides on the same form
'frmMain'. I can get everything to work if I enter a constant into the
second value of the Insert Statement (it is currently a '36'). The
value that I want in there is from a text box called txtEquipIDHolder.
I have tried everything I know to get that to work but I'm stuck...
Private Sub cboFailures_NotInList(NewData As String, Response As
Integer)
Dim db As Database

Dim LSQL As String
Dim LResponse As Integer
Dim ctl As Control
Dim ctlEquip As Control
On Error GoTo Err_Execute

'Category combo box control
Set ctl = Me!cboFailures
Set ctlEquip = Me!txtEquipIDHolder

LResponse = msgBox(NewData & " is a new item. Do you wish to add
it to the combo box?", vbYesNo, "Add Item")
'Debug msgBox (txtEquip & " works!!!")

'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 Failures (FailureName,EquipmentID) values
('" & NewData & "','36')"
db.Execute LSQL, dbFailOnError
'show new Value
Me.cboFailures = Null
Me.cboFailures.Requery
Me.cboFailures = Me.cboFailures.ItemData(0)

'Reset Database
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

Try LSQL = "insert into Failures (FailureName,EquipmentID) values
('" & NewData & "','" & txtEquipIDHolder & "')"

Bruce
Jan 9 '07 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
6912
by: soni29 | last post by:
hi, i have a small question regarding sql, there are two tables that i need to work with on this, one has fields like: Table1: (id, name, street, city, zip, phone, fax, etc...) about 20 more...
1
4082
by: Maria | last post by:
Hello I have not used db2 in a long time, and I have this very long insert script, which is giving me an error of duplicated inserts. My question is how can I put something in the statment so...
8
2032
by: 73blazer | last post by:
Hello, I'm looking for a way to make some of my insert templates more readable by placing comments in between the values. I cannot seem to find a way to do this with DB2, is there a way? I'm...
2
2740
by: .Net Newbie | last post by:
Hello, I am somewhat new to .Net and currently working on an intranet site using C# going against SQL Server 2k. I am accepting personal information on a single webform and trying to insert the...
0
1046
by: isaac2004 | last post by:
hello im trying to make a page that reads simple user information and posts them to a table. the user can edit, delete and add new records, through a form on the page.using SQLs modifications...
0
1344
by: isaac2004 | last post by:
im trying to make a page that reads simple user information and posts them to a table. the user can edit, delete and add new records, through a form on the page.using SQLs modifications like...
8
3661
by: slb813 | last post by:
Hello, I am having a problem that I can't seem to work out. I am running Apache 2.2 on a Windows XP platform, using PHP5. I am attempting to insert a row into a MS Access data base with a PHP...
14
1334
by: thetaamommy | last post by:
CREATE Table CO(CustID int, OfficerSID varchar(10), OfficerRank tinyint) Insert Into CO VALUES (1, 'KURT', 1) Insert Into CO VALUES (1, 'ALEX', 2) Insert Into CO
2
1891
by: Dinesh | last post by:
Hi experts, I am working on SQL Server 2005. Now i have to write a query which will extract some information from a table. My main table is having few columns supose 3 columns. EmpID ...
0
7203
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7087
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7281
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
1
6993
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
1
5014
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4675
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3168
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
1514
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
737
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.