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.scrSt udent) Then
C1 = 1: TDate = Me![scr1Date]
Do Until C1 = CInt(Mid(Active Control.Name, 3, 2))
TDate = DateAdd("d", 1, TDate)
C1 = C1 + 1
Loop
TypeAttend = DLookup("AttTyp e", "Attend", "[AttStudent] = " &
Me![scrStudent] & " AND [AttDate] = #" & Format(TDate, "mm/dd/yy") & "#")
If IsNull(TypeAtte nd) 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.SetWarnin gs False
RecDetect = DLookup("[scrStudent]", "Attend", "[AttStudent] = " &
Me![scrStudent] & " AND [AttDate] = #" & Format(TDate, "mm/dd/yy") & "#")
If IsNull(RecDetec t) 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.AttSt udent)=" & Me![scrStudent] & ") AND" _
& "((Attend.AttDa te)=#" & Format(TDate, "mm/dd/yy") & "#));"
DoCmd.RunSQL StrSQL
End If
DoCmd.SetWarnin gs True
Call RefDates
End If
End Function 3 1928
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.scrSt udent) Then C1 = 1: TDate = Me![scr1Date]
Do Until C1 = CInt(Mid(Active Control.Name, 3, 2)) TDate = DateAdd("d", 1, TDate) C1 = C1 + 1 Loop
TypeAttend = DLookup("AttTyp e", "Attend", "[AttStudent] = " & Me![scrStudent] & " AND [AttDate] = #" & Format(TDate, "mm/dd/yy") & "#") If IsNull(TypeAtte nd) 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.SetWarnin gs False RecDetect = DLookup("[scrStudent]", "Attend", "[AttStudent] = " & Me![scrStudent] & " AND [AttDate] = #" & Format(TDate, "mm/dd/yy") & "#") If IsNull(RecDetec t) 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.AttSt udent)=" & Me![scrStudent] & ") AND" _ & "((Attend.AttDa te)=#" & Format(TDate, "mm/dd/yy") & "#));" DoCmd.RunSQL StrSQL End If DoCmd.SetWarnin gs True Call RefDates End If End Function
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).
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******* *********@news0 2.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.scrSt udent) Then C1 = 1: TDate = Me![scr1Date]
Do Until C1 = CInt(Mid(Active Control.Name, 3, 2)) TDate = DateAdd("d", 1, TDate) C1 = C1 + 1 Loop
TypeAttend = DLookup("AttTyp e", "Attend", "[AttStudent] = " & Me![scrStudent] & " AND [AttDate] = #" & Format(TDate, "mm/dd/yy") & "#") If IsNull(TypeAtte nd) 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.SetWarnin gs False RecDetect = DLookup("[scrStudent]", "Attend", "[AttStudent] = " & Me![scrStudent] & " AND [AttDate] = #" & Format(TDate, "mm/dd/yy") & "#") If IsNull(RecDetec t) 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.AttSt udent)=" & Me![scrStudent] & ") AND" _ & "((Attend.AttDa te)=#" & Format(TDate, "mm/dd/yy") & "#));" DoCmd.RunSQL StrSQL End If DoCmd.SetWarnin gs True Call RefDates End If End Function
This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
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 atmosphere.
Good food.", " (Harry Houdini - 03/01/2004)");
INSERT INTO `reviews` VALUES("", "Le Chow Place", "Lunch", "yada yada",
" (Herbert Hoover - 03/03/2004)");
INSERT INTO `reviews` VALUES("", "Golden Dragon", "Lunch", "Exquisite.
|
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 servers using
sp_addlinkedserver on both database servers.
When I call the Commit API of oledb I get the following error:
Error state: 1, Severity: 19, Server: TST-PROC22, Line#: 1, msg:
|
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 must be UPDATED, if not, they
must be INSERTED.
Logically then, I would like to SELECT * FROM <TABLE>
WHERE ....<Values entered here>, and then IF FOUND
UPDATE <TABLE> SET .... <Values entered here> ELSE
INSERT INTO <TABLE> VALUES <Values...
|
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 the INSERT in the SPL. I got an error stating that
there was no open cursor.
I have done some research on here and found that it's not
possible to issue a COMMIT inside an SPL. But it can be done
so on the client side. Can anyone shade me some...
|
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 probably missing something basic.
I have
insert into ken.snyder id1,id2,id3
values (
| |
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 example I had to go by
'INSERT INTO tblCustomers (CustomerID, , )
|
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 sqldatasource control,
there is no need of opening and closing a connection. Also there is no
need to write connection string. When i am selecting table from
sqldatasource and writing insert statement in C# code, its working
fine. When I am...
|
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 appropriately moved further
down? From a cursory search of the libc documentation I can't find such
a function. Will I have to write it myself?
Thanks.
|
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 sql server is my backend server.
This error occured whenever i step through and when it reaches rs.update it jux hangs down there and thereafter it shwn the aforementioned error. I am using the RecordSet properties to add the values. Can I use...
|
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
using MS-Access 2000 database table for this app. Note that the
datatype of all the fields mentioned above are Text. Apart from the
above columns, there's another column in the DB table named
'RegDateTime' whose datatype is Date/Time which is...
|
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
| |
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
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 then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
|
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |