473,385 Members | 1,356 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,385 software developers and data experts.

Need someone else's eyes Update Statement Syntax error

Hello everyone,
I keep getting a syntax error in my update statement. The only thing that I notice is
that although the columns in my table have the same name as the fields on the form the compiler keeps changing the name eg

strSQL = strSQL & "', Equipment='" & Me![equipment] (compiler format)

should read
strSQL = strSQL & "', Equipment='" & Me![Equipment].

Also I am trying to format the where clause criteria with a combo box that has two columns. I am wondering if this is giving the error but the compiler does not highlight it.
In the combo box's after update event this works fine

Criteria = "[AirlineCode] &' '& [flightnuminout]" = " & [cboAdhoc]"

rsCust.FindFirst Criteria.

However I am not sure how to concatenate two columns from the same table in the where clause.

I think maybe

1. 'strSQL = strSQL & " WHERE "[AirlineCode] &"' '"& [Flightnuminout]" = " & [cboAdhoc]"
2.strSQL = strSQL & "' WHERE AirlineCode = '" & [cboAdhoc] & ""

3. strSQL = strSQL & "' WHERE AirlineCode And Flightnuminout= '" & [cboAdhoc] & ""
Apr 18 '07 #1
4 1597
pks00
280 Expert 100+
Ok, first off, your first sql, did u end it with single quotes or forget to post that?
i.e.
strSQL = strSQL & "', Equipment='" & Me![Equipment].

should be

strSQL = strSQL & "', Equipment='" & Me![Equipment]. & "'"


Secondly, what are you trying to achieve here

strSQL = strSQL & "' WHERE AirlineCode And Flightnuminout= '" & [cboAdhoc] & ""

Is cboAdhoc a combination of both ArlineCode and Flightnuminout concatenated? If so then try this

strSQL = strSQL & "' WHERE AirlineCode & Flightnuminout= '" & [cboAdhoc] & ""

how many columns in cboAdhoc, u couldbe looking at the wrong column
to verify the value, type this in

msgbox cboAdhoc
Apr 18 '07 #2
Thanks for the sql syntax corrections.
My combox is still giving me trouble

The combobox consists of two columns. I search the records to edit with this combobox code

Private Sub cboAdhoc_AfterUpdate()
Dim d As DAO.Database
Dim rsCust As DAO.Recordset
Dim Criteria As String
rsCus
Set d = CurrentDb
Set rsAdhoc = d.OpenRecordset("tblflight1", dbOpenDynaset)
'selects concatenated fields in access table
Criteria = "[AirlineCode] &' '& [flightnuminout]" = " & [cboAdhoc]"

rsAdhoc.FindFirst Criteria


Me!Equipment = rsAdhoc("Equipment")
Me!AirlineCode = rsAdhoc("AirlineCode")
Me!AirlineCode = UCase(Me!AirlineCode)
Me!Flightnuminout = rsAdhoc("Flightnuminout")

This works fine. If this syntax is wrong please correct me.

However in the update table statement I keep getting an error as if it is only recognizing the airlinecode and not the flightnuminout.

When I click on the combobox it displays both columns airlinecode and flightnuminout.

However after it is selected it displays only airlinecode.

I wonder if the combobox can be read as an index eg in sql statement

Where AirlineCode & Flightnuminout = & [cboAdhoc.Value()]" would this allow it to read the two coulumns?
When I try I get an error
Apr 18 '07 #3
pks00
280 Expert 100+
When I click on the combobox it displays both columns airlinecode and flightnuminout.

However after it is selected it displays only airlinecode.
this means u have to reference them using column numbers

try this

strSQL = strSQL & "' WHERE AirlineCode = '" & cboAdhoc.Column(0) & ' AND Flightnuminout = '" & cboAdhoc.Column(1) & ""


cboAdhoc.Column(0) returns value in 1st column
cboAdhoc.Column(1) returns value in 2nd column
etc

If any fields are numeric then u drop the wrapping in single quotes
Apr 18 '07 #4
Thank you so much this both values are being read in the update statement.

However, the syntax error has come back. After I click the command button a message box from access comes up appearing as if it has passed all the values from the form to the table columns but then the update syntax error comes up again. Here is all my code.

f IsNull(Me!AirlineCode) Then
MsgBox "AirlineCode is a Required Entry.", 48
Me!AirlineCode.SetFocus
Exit Sub
End If

If IsNull(Me!flightnuminout) Then
MsgBox "Flightnuminout is a Required Entry.", 48
Me!flightnuminout.SetFocus
Exit Sub
End If

If IsNull(Me!cboAdhoc) Then
MsgBox "Is this a new addition? If so, use the Add button below to save this record."
Me!cmdAddRec0.SetFocus
Exit Sub
End If


'**** Save Changes ****
Dim db As Database
Set db = CurrentDb
Dim strSQL As String

strSQL = "UPDATE tblflight1 "

strSQL = strSQL & "',SET AirlineCode='" & Me![AirlineCode] & "'"
strSQL = strSQL & "', Equipment='" & Me![Equipment] & "'"
strSQL = strSQL & "', Flightnuminout='" & Me![flightnuminout] & "'"
strSQL = strSQL & "', AirlineName='" & Me![AirlineName] & "'"
strSQL = strSQL & "', STA='" & Me![STA] & "'"
strSQL = strSQL & "', STD='" & Me![STD] & "'"
strSQL = strSQL & "',RouteTo='" & Me![RouteTo] & "'"
strSQL = strSQL & "',RouteFrom='" & Me![RouteFrom] & "'"
strSQL = strSQL & "',Configuration='" & Me![Configuration] & "'"
strSQL = strSQL & "',ProgramIN='" & Me![ProgramIN] & "'"
strSQL = strSQL & "',ProgramOUT='" & Me![ProgramOUT] & "'"
strSQL = strSQL & "',Remarks='" & Me![Remarks] & "'"
strSQL = strSQL & "',Montharr='" & Me![Montharr] & "'"
strSQL = strSQL & "',Monthactivity='" & Me![Monthactivity] & "'"
strSQL = strSQL & "',Arrtime='" & Me![arrtime] & "'"
strSQL = strSQL & "',Deptime='" & Me![deptime] & "'"
strSQL = strSQL & "',Arrivaldate='" & Me![Arrivaldate] & "'"
strSQL = strSQL & "',Departuredate='" & Me![Departuredate] & "'"
strSQL = strSQL & "',WK1='" & Me![WK1] & "'"
strSQL = strSQL & "',WK2='" & Me![WK2] & "'"
strSQL = strSQL & "',WK3='" & Me![WK3] & "'"
strSQL = strSQL & "',WK4='" & Me![WK4] & "'"



strSQL = strSQL & " 'WHERE AirlineCode = '" & cboAdhoc.Column(0) & "' AND Flightnuminout = '" & cboAdhoc.Column(1) & ""
MsgBox strSQL

db.Execute strSQL

MsgBox "Changes to " & Me!AirlineCode & " have been saved."

'**** clear the controls to add more flights ****
Call ClearControls
Apr 19 '07 #5

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

Similar topics

3
by: Robert Mark Bram | last post by:
Hi All! I have the following two methods in an asp/jscript page - my problem is that without the update statement there is no error, but with the update statement I get the following error: ...
7
by: Dave | last post by:
I have 2 tables, one with names, and another with addresses, joined by their CIVICID number (unique to the ADDRESSINFO table) in Oracle. I need to update a field in the NAMEINFO table for a...
3
by: Alex | last post by:
Hi folks, Hopefully this is a simple fix, but I keep getting Syntax error with this statement in an MS SQL DTS statement and in Query Analyzer: Update A Set A.deptcode = A.deptcode, A.type =...
8
by: Lauren Quantrell | last post by:
In VBA, I constructed the following to update all records in tblmyTable with each records in tblmyTableTEMP having the same UniqueID: UPDATE tblMyTable RIGHT JOIN tblMyTableTEMP ON...
3
by: Falco Vermeer | last post by:
Hi, I tried to use the following query to update a value in one table with a value from another table: UPDATE tbl1 SET col1 = tbl2.col2 FROM tbl1, tbl2 WHERE tbl1. = tbl2.
3
by: Colin Spalding | last post by:
In Access, if I want to update one table with information from another, all I need to do is to create an Update query with the two tables, link the primary keys and reference the source...
8
by: Bshealey786 | last post by:
Okay im doing my final project for my first computer science class(its my major, so it will be my first of many), but anyway im a beginner so im not to great with C++ yet. Anyway this is the error...
1
by: teddymeu | last post by:
Hi Guys, trying to bulk insert a csv file into my SQL database from an asp.net vb web app/form page that the user uploads, my problem is that im new to all this and although the SQL statement...
4
by: fatboySudsy | last post by:
Hi, I have constructed a client program that has given me some error codes that i just cannot see. I was wondering if a different set of eyes with much more experience than me could help me out. ...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
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?
1
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 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.