473,386 Members | 1,821 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

I cant save data from form to table.(Urgent)

12
I'm creating a database for my company. Here we have errors form to calculate the errors done. The data entered in this form need to update into the errors table. This is my code but i'm getting error "Run-time error. Syntax error in INSERT INTO statement".

Private Sub CmdSave_Enter()

Dim strselect As String
Dim strinsert As String
Dim flag As Boolean
Dim temp As String
Dim msgval As Integer


flag = True


'Below query Selects the recordset as per the conditions
strselect = "Select * FROM Errors where Date = date() AND Sub-Process='" & txtSub.Value & "'"


'Below Query inserts the Review time as a new record
strinsert = "INSERT INTO Errors (Date,LoginID,Sub-Process, Incorrect Data) values (date(),'" & Lgn & "', '" & txtSub.Value & "','" & txt1.Value & "')"



'Setting connection with different tables

Set cn = Application.CurrentProject.Connection 'Setting connection to the table Review_Time
Set rs = New ADODB.Recordset 'Selecting the records from the Review_Time Table
Set rs2 = New ADODB.Recordset 'For updating and inserting the records in the Review_Time Table


On Error GoTo errorhandler


errorhandler:

If flag = True Then

rs2.Open strinsert, cn, adOpenForwardOnly, adLockOptimistic

MsgBox "Reviewed Volume Added"

End If

Hope someone can guide me.Thank you in advance.
Nov 28 '07 #1
3 1606
MikeTheBike
639 Expert 512MB
I'm creating a database for my company. Here we have errors form to calculate the errors done. The data entered in this form need to update into the errors table. This is my code but i'm getting error "Run-time error. Syntax error in INSERT INTO statement".

Private Sub CmdSave_Enter()

Dim strselect As String
Dim strinsert As String
Dim flag As Boolean
Dim temp As String
Dim msgval As Integer


flag = True


'Below query Selects the recordset as per the conditions
strselect = "Select * FROM Errors where Date = date() AND Sub-Process='" & txtSub.Value & "'"


'Below Query inserts the Review time as a new record
strinsert = "INSERT INTO Errors (Date,LoginID,Sub-Process, Incorrect Data) values (date(),'" & Lgn & "', '" & txtSub.Value & "','" & txt1.Value & "')"



'Setting connection with different tables

Set cn = Application.CurrentProject.Connection 'Setting connection to the table Review_Time
Set rs = New ADODB.Recordset 'Selecting the records from the Review_Time Table
Set rs2 = New ADODB.Recordset 'For updating and inserting the records in the Review_Time Table


On Error GoTo errorhandler


errorhandler:

If flag = True Then

rs2.Open strinsert, cn, adOpenForwardOnly, adLockOptimistic

MsgBox "Reviewed Volume Added"

End If

Hope someone can guide me.Thank you in advance.
Hi

I don't think you can "open" an ACTION query.

Try something like this

CurrentProject.Connection.Execute strinsert, ,adExecuteNoRecords

??

MTB
Nov 28 '07 #2
abie16
12
Thanks for the immediate reply MTB but it still dont work.
Nov 28 '07 #3
MikeTheBike
639 Expert 512MB
Thanks for the immediate reply MTB but it still dont work.
OK, so do you have the same error ??

My only suggestion without more information would be to enclose all references to the Date FIELD in square brackets ie [Date].

Does the SELECT query work?

BTW don't use key words or function names for field/variable names, it might not end in tears, but it will probably give problems at some point (speaking from experience here - naughty boy!).

MTB
Nov 28 '07 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

4
by: Bruce Skamser | last post by:
I added a field to a table and when I go to the form to add a textbox control, I can't bind it to the field in the table. It doesn't come up in the list of fields in the control source dropdown. ...
0
by: amrhi | last post by:
Hy Guys , Can anybody help me ? I try to make small web database in my unit. Some of fields have on change behaviour to get other data that automatically filled other text field. But when i try to...
1
by: QCLee | last post by:
Hello Sir, Im here again asking for help. I have a form and a subform relate to HVAC Windward Table. i have a SAVE button on the form that when clicked it saves data on the HVAC Windward Table but...
3
by: =?Utf-8?B?YzY3NjIyOA==?= | last post by:
Hi all, I have a question for you. I have a .csv file which has many lines of data. Each line has many data fields which are delimited by ",". Now I need to extract part of data from this...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
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
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,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.