- Dim Request As String, rsData As Recordset
-
-
If Me.cmdUpdate.Caption = "&Save" Then
-
-
Request = "INSERT INTO tblMasterData VALUES '" & Replace(Me.txtID.Text, " '", "''") & "'," & _
-
"'" & Replace(Me.txtFName.Text, "'", "''") & "'," & _
-
"'" & Replace(Me.cboPosition.Text, "'", "''") & "'," & _
-
"'" & Replace(Me.txtStatus.Text, "'", "''") & "'," & _
-
"'" & Replace(Me.txtRate.Text, "'", "''") & "'," & _
-
"'" & Replace(Me.dtpStart.value, "'", "''") & "'," & _
-
"'" & Replace(Me.dtpEnd.value, "'", "''") & "'," & _
-
"'" & Replace(Me.txtAge.Text, "'", "''") & "'," & _
-
"'" & Replace(Me.txtAddress.Text, "'", "''") & "'"
-
-
ElseIf Me.cmdUpdate.Caption = "&Update" Then
-
-
Request = "UPDATE tblMasterData SET EmpName ='" & Replace(Me.txtFName.Text, "'", "''") & "'," & _
-
"EmpPosition = '" & Replace(Me.cboPosition.Text, "'", "''") & "'," & _
-
"EmpStatus = '" & Replace(Me.txtStatus.Text, "'", "''") & "'," & _
-
"EmpRate = '" & Replace(Me.txtRate.Text, "'", "''") & "'," & _
-
"DateHired = '" & Replace(Me.dtpStart.value, "'", "''") & "'," & _
-
"Endo = '" & Replace(Me.dtpEnd.value, "'", "''") & "'," & _
-
"EmpAge = '" & Replace(Me.txtAge.Text, "'", "''") & "'," & _
-
"EmpAddress = '" & Replace(Me.txtAddress.Text, "'", "''") & "'"
-
-
Request = Request & " WHERE EmpID = " & Me.txtID.Text
-
-
cmdAdd.Caption = "&Add"
-
End If
-
-
DBConn.Execute Request
Hi,
I don't think there is any Syntax Error in the Query, But you may try to Add Open & Close Parenthesis in the Insert Query and Use the Format function for Date in Both the Queries
So the resulting query will look like -
Dim Request As String, rsData As Recordset
-
-
If Me.cmdUpdate.Caption = "&Save" Then
-
-
Request = "INSERT INTO tblMasterData VALUES ('" & Replace(Me.txtID.Text, " '", "''") & "'," & _
-
"'" & Replace(Me.txtFName.Text, "'", "''") & "'," & _
-
"'" & Replace(Me.cboPosition.Text, "'", "''") & "'," & _
-
"'" & Replace(Me.txtStatus.Text, "'", "''") & "'," & _
-
"'" & Replace(Me.txtRate.Text, "'", "''") & "'," & _
-
"'" & Format(Me.dtpStart.value, "MM/dd/yyyy") & "'," & _
-
"'" & Format(Me.dtpEnd.value, "MM/dd/yyyy") & "'," & _
-
"'" & Replace(Me.txtAge.Text, "'", "''") & "'," & _
-
"'" & Replace(Me.txtAddress.Text, "'", "''") & "')"
-
-
ElseIf Me.cmdUpdate.Caption = "&Update" Then
-
Request=""
-
Request = "UPDATE tblMasterData SET EmpName ='" & Replace(Me.txtFName.Text, "'", "''") & "'," & _
-
"EmpPosition = '" & Replace(Me.cboPosition.Text, "'", "''") & "'," & _
-
"EmpStatus = '" & Replace(Me.txtStatus.Text, "'", "''") & "'," & _
-
"EmpRate = '" & Replace(Me.txtRate.Text, "'", "''") & "'," & _
-
"DateHired = '" & Format(Me.dtpStart.value, "MM/dd/yyyy") & "'," & _
-
"Endo = '" & Format(Me.dtpEnd.value, "MM/dd/yyyy") & "'," & _
-
"EmpAge = '" & Replace(Me.txtAge.Text, "'", "''") & "'," & _
-
"EmpAddress = '" & Replace(Me.txtAddress.Text, "'", "''") & "'"
-
-
Request = Request & " WHERE EmpID = " & Me.txtID.Text
-
-
cmdAdd.Caption = "&Add"
-
End If
-
-
DBConn.Execute Request
-
-
And Also use Val Function for Numeric values without using single quotes whereever necessary in the Query
Regards
Vijay.R
2 1648
Hi,
I don't think there is any Syntax Error in the Query, But you may try to Add Open & Close Parenthesis in the Insert Query and Use the Format function for Date in Both the Queries
So the resulting query will look like -
Dim Request As String, rsData As Recordset
-
-
If Me.cmdUpdate.Caption = "&Save" Then
-
-
Request = "INSERT INTO tblMasterData VALUES ('" & Replace(Me.txtID.Text, " '", "''") & "'," & _
-
"'" & Replace(Me.txtFName.Text, "'", "''") & "'," & _
-
"'" & Replace(Me.cboPosition.Text, "'", "''") & "'," & _
-
"'" & Replace(Me.txtStatus.Text, "'", "''") & "'," & _
-
"'" & Replace(Me.txtRate.Text, "'", "''") & "'," & _
-
"'" & Format(Me.dtpStart.value, "MM/dd/yyyy") & "'," & _
-
"'" & Format(Me.dtpEnd.value, "MM/dd/yyyy") & "'," & _
-
"'" & Replace(Me.txtAge.Text, "'", "''") & "'," & _
-
"'" & Replace(Me.txtAddress.Text, "'", "''") & "')"
-
-
ElseIf Me.cmdUpdate.Caption = "&Update" Then
-
Request=""
-
Request = "UPDATE tblMasterData SET EmpName ='" & Replace(Me.txtFName.Text, "'", "''") & "'," & _
-
"EmpPosition = '" & Replace(Me.cboPosition.Text, "'", "''") & "'," & _
-
"EmpStatus = '" & Replace(Me.txtStatus.Text, "'", "''") & "'," & _
-
"EmpRate = '" & Replace(Me.txtRate.Text, "'", "''") & "'," & _
-
"DateHired = '" & Format(Me.dtpStart.value, "MM/dd/yyyy") & "'," & _
-
"Endo = '" & Format(Me.dtpEnd.value, "MM/dd/yyyy") & "'," & _
-
"EmpAge = '" & Replace(Me.txtAge.Text, "'", "''") & "'," & _
-
"EmpAddress = '" & Replace(Me.txtAddress.Text, "'", "''") & "'"
-
-
Request = Request & " WHERE EmpID = " & Me.txtID.Text
-
-
cmdAdd.Caption = "&Add"
-
End If
-
-
DBConn.Execute Request
-
-
And Also use Val Function for Numeric values without using single quotes whereever necessary in the Query
Regards
Vijay.R
IT DID THE JOB! Sir thank you so much for that. one more thing, could you please explain to me what's the difference between the first one that i use with the date and the one you give using that format function? idid some experimenting and you're right, it does work with the mm/dd/yyy format. Thankkk you so much again for your reply.
Sign in to post your reply or Sign up for a free account.
Similar topics
by: alexz |
last post by:
valuA = (request.form("toadd"))
If valuA = "" then
SQL = "UPDATE CourseReg SET attended='Active' WHERE ID
IN("&request.form("toadd")&")"
Set RS = MyConn.Execute(SQL)
End If
MyConn.Close
Set...
|
by: Tim::.. |
last post by:
Can someone please tell me why I keep getting the following error from the
code below!
Error: INSERT statement conflicted with COLUMN FOREIGN KEY constraint...
|
by: jinhy82 |
last post by:
Hi! I am currently creating a Registration form which contained: UserID
Password, FirstName and LastName.
These details would be inserted into Ms Access when I click submi
button. But I...
|
by: John Øllgård Jensen |
last post by:
Hi
Using MS Asccess 2000:
In a query I'm trying to create a new field with following expression:
FilmDate: Left(,4)
The field "FilmNo" is another text field in the query.
This is...
|
by: M |
last post by:
TableAdapter Configuration Wizard do not create Insert Statement(It Creates
SELECT, UPDATE, DELETE statements) So if I try using
Myadapter.update(MydataTable) to add a new row.
I get Error...
|
by: irisbu |
last post by:
Hello everybody!
I have created a form in word to automatically create mail merges from an access database.
I have the following code:
Private Sub CommandButton1_Click()
Documents.Open...
|
by: Yesurbius |
last post by:
I am receiving the following error when attempting to run my query. In my mind - this error should not be happening - its a straight-forward query with a subquery. I am using Access 2003 with all...
|
by: Ed Pisa |
last post by:
Hello,
I have been working with this problem now for several days. I can delete and Update my data but I can not get it to insert a new record. I receive the syntax error insert into. I am not...
|
by: Ed Pisa |
last post by:
Hello,
I have been working with this problem now for several days. I can delete and Update my data but I can not get it to insert a new record. I receive the syntax error insert into. I am not...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
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...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
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,...
|
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...
|
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: 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...
| |