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

SQL Insert Into Error

I've modified sql text and now i'm getting a syntax error that I cannot
figure out....anyone?
error occurs at the Insert Into line but the entire function is given in
case you need it.
---
Function ThisIs()
Dim TDate As Date, C1 As Integer, StrSQL As String, TypeAttend, RecDetect
If Not IsNull(Me.scrStudent) Then
C1 = 1: TDate = Me![scr1Date]

Do Until C1 = CInt(Mid(ActiveControl.Name, 3, 2))
TDate = DateAdd("d", 1, TDate)
C1 = C1 + 1
Loop

TypeAttend = DLookup("AttType", "Attend", "[AttStudent] = " &
Me![scrStudent] & " AND [AttDate] = #" & Format(TDate, "mm/dd/yy") & "#")
If IsNull(TypeAttend) Then
TypeAttend = 0
End If
TypeAttend = TypeAttend + 1
If TypeAttend > 4 Then
TypeAttend = 0
End If
If TypeAttend = 3 Then
Dim TradeName
Me.cboTradeWith.Visible = True
TradeName = Me.cboTradeWith
End If
DoCmd.SetWarnings False
RecDetect = DLookup("[scrStudent]", "Attend", "[AttStudent] = " &
Me![scrStudent] & " AND [AttDate] = #" & Format(TDate, "mm/dd/yy") & "#")
If IsNull(RecDetect) Then
StrSQL = "INSERT INTO Attend ( AttStudent, AttDate, AttType, tradewith )
" _
& "SELECT " & Me![scrStudent] & " AS F1, #" _
& Format(TDate, "mm/dd/yy") & "# AS F2, " & TypeAttend & " AS F3, " &
TradeName & " AS F4; "
DoCmd.RunSQL StrSQL
Else
StrSQL = "UPDATE Attend SET Attend.AttType = " & TypeAttend _
& " WHERE (((Attend.AttStudent)=" & Me![scrStudent] & ") AND" _
& "((Attend.AttDate)=#" & Format(TDate, "mm/dd/yy") & "#));"
DoCmd.RunSQL StrSQL
End If
DoCmd.SetWarnings True
Call RefDates
End If
End Function
Dec 18 '05 #1
3 1915
Anyone good with SQL..I'm still stuck. I've been at it for 6 hours this
morning
"shifty shaker" <SS***@pioneers.net> wrote in message
news:cb****************@news02.roc.ny...
I've modified sql text and now i'm getting a syntax error that I cannot
figure out....anyone?
error occurs at the Insert Into line but the entire function is given in
case you need it.
---
Function ThisIs()
Dim TDate As Date, C1 As Integer, StrSQL As String, TypeAttend, RecDetect
If Not IsNull(Me.scrStudent) Then
C1 = 1: TDate = Me![scr1Date]

Do Until C1 = CInt(Mid(ActiveControl.Name, 3, 2))
TDate = DateAdd("d", 1, TDate)
C1 = C1 + 1
Loop

TypeAttend = DLookup("AttType", "Attend", "[AttStudent] = " &
Me![scrStudent] & " AND [AttDate] = #" & Format(TDate, "mm/dd/yy") & "#")
If IsNull(TypeAttend) Then
TypeAttend = 0
End If
TypeAttend = TypeAttend + 1
If TypeAttend > 4 Then
TypeAttend = 0
End If
If TypeAttend = 3 Then
Dim TradeName
Me.cboTradeWith.Visible = True
TradeName = Me.cboTradeWith
End If
DoCmd.SetWarnings False
RecDetect = DLookup("[scrStudent]", "Attend", "[AttStudent] = " &
Me![scrStudent] & " AND [AttDate] = #" & Format(TDate, "mm/dd/yy") & "#")
If IsNull(RecDetect) Then
StrSQL = "INSERT INTO Attend ( AttStudent, AttDate, AttType,
tradewith ) " _
& "SELECT " & Me![scrStudent] & " AS F1, #" _
& Format(TDate, "mm/dd/yy") & "# AS F2, " & TypeAttend & " AS F3, " &
TradeName & " AS F4; "
DoCmd.RunSQL StrSQL
Else
StrSQL = "UPDATE Attend SET Attend.AttType = " & TypeAttend _
& " WHERE (((Attend.AttStudent)=" & Me![scrStudent] & ") AND" _
& "((Attend.AttDate)=#" & Format(TDate, "mm/dd/yy") & "#));"
DoCmd.RunSQL StrSQL
End If
DoCmd.SetWarnings True
Call RefDates
End If
End Function

Dec 18 '05 #2
My screen shows
)SELECT

) no space SELECT
rather than
) space SELECT

Is this the problem? I don't know. You could check.

I always do a debug.print of dynamic SQL during devlopment so that I
can see that what I intended to say is not actually what I said. If
it''s not doing what I want I paste it into the query wizard and mess
with it there until I get it the way I want it. Then I bring that back
to VBA as a model and mess with my code until it gives me the model.

I also never use object values (read Form Controls) default values
directly in an SQL string. I create variables of the correct type, fill
them with values from the Forms Controls, run some checking of the
values or what ifs (e.g, what if the control is empty, what if we check
treat a combo box column as a number and actually its null etc).

Dec 18 '05 #3
On Sun, 18 Dec 2005 17:43:20 GMT, "shifty shaker" <SS***@pioneers.net>
wrote:
Anyone good with SQL..I'm still stuck. I've been at it for 6 hours this
morning
"shifty shaker" <SS***@pioneers.net> wrote in message
news:cb****************@news02.roc.ny...
I've modified sql text and now i'm getting a syntax error that I cannot
figure out....anyone?
error occurs at the Insert Into line but the entire function is given in
case you need it.
---
Function ThisIs()
Dim TDate As Date, C1 As Integer, StrSQL As String, TypeAttend, RecDetect
TypeAttend and RecDetect are being dimensioned as variants. Is that
what you want? If not, make them what you want them to be.
If Not IsNull(Me.scrStudent) Then
C1 = 1: TDate = Me![scr1Date]

Do Until C1 = CInt(Mid(ActiveControl.Name, 3, 2))
TDate = DateAdd("d", 1, TDate)
C1 = C1 + 1
Loop

TypeAttend = DLookup("AttType", "Attend", "[AttStudent] = " &
Me![scrStudent] & " AND [AttDate] = #" & Format(TDate, "mm/dd/yy") & "#")
If IsNull(TypeAttend) Then
TypeAttend = 0
End If
TypeAttend = TypeAttend + 1
If TypeAttend > 4 Then
TypeAttend = 0
End If
If TypeAttend = 3 Then
Dim TradeName
The above dimensions TradeName as a variant. I think it is better
practice to:

Dim Tradename as string
Me.cboTradeWith.Visible = True
TradeName = Me.cboTradeWith
End If
DoCmd.SetWarnings False
RecDetect = DLookup("[scrStudent]", "Attend", "[AttStudent] = " &
Me![scrStudent] & " AND [AttDate] = #" & Format(TDate, "mm/dd/yy") & "#")
If IsNull(RecDetect) Then
StrSQL = "INSERT INTO Attend ( AttStudent, AttDate, AttType,
tradewith ) " _
& "SELECT " & Me![scrStudent] & " AS F1, #" _
& Format(TDate, "mm/dd/yy") & "# AS F2, " & TypeAttend & " AS F3, " &
TradeName & " AS F4; "
Sure does look to me like TradeName isn't a number. As such,
shouldn't it be enlosed within quotes?

It also looks like the only time you actually set TradeName is when
TypeAttend = 3 (see above).

Could that be the problem?

Do what Lyle says. Familiarize yourself with the debugging window.

mike
DoCmd.RunSQL StrSQL
Else
StrSQL = "UPDATE Attend SET Attend.AttType = " & TypeAttend _
& " WHERE (((Attend.AttStudent)=" & Me![scrStudent] & ") AND" _
& "((Attend.AttDate)=#" & Format(TDate, "mm/dd/yy") & "#));"
DoCmd.RunSQL StrSQL
End If
DoCmd.SetWarnings True
Call RefDates
End If
End Function



Dec 20 '05 #4

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

Similar topics

15
by: Jack | last post by:
I have a text file of data in a file (add2db.txt) where the entries are already entered on separate lines in the following form: INSERT INTO `reviews` VALUES("", "Tony's", "Lunch", "Great...
7
by: iqbal | last post by:
Hi all, We have an application through which we are bulk inserting rows into a view. The definition of the view is such that it selects columns from a table on a remote server. I have added the...
16
by: Philip Boonzaaier | last post by:
I want to be able to generate SQL statements that will go through a list of data, effectively row by row, enquire on the database if this exists in the selected table- If it exists, then the colums...
6
by: harborboy76 | last post by:
Hi, I am trying to insert a large number of rows into a table inside a SPL. But every time, I run the SPL, the table is locked because of the INSERT. When I tried to issue a COMMIT, right after...
8
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...
3
by: MP | last post by:
Hi Posted this several hours ago to another ng but it never showed up thought i'd try here. using vb6, ado, .mdb, jet4.0, no access given table tblJob with field JobNumber text(10) 'The...
3
by: mahajanvit | last post by:
Hi one and all I got this problem during my project. So in order to solve this I made a very small application. I am trying to insert using SP and sqldatasource control. I know that while using...
9
by: anachronic_individual | last post by:
Hi all, Is there a standard library function to insert an array of characters at a particular point in a text stream without overwriting the existing content, such that the following data in...
2
by: technocraze | last post by:
Hi guys, I have encountered this error when updating the values to the MS Acess table. Error : Update on linked table failed. ODBC sql server error Timeout expired. MS Acess is my front end and...
6
by: rn5a | last post by:
During registration, users are supposed to enter the following details: First Name, Last Name, EMail, UserName, Password, Confirm Password, Address, City, State, Country, Zip & Phone Number. I am...
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...
0
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...
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...
1
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...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
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
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
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
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

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.