Im having problem running the program. Its say i have incorrect syntax at my strsql coding - Private Sub ComboBox1_Change()
-
-
Dim rst As ADODB.Recordset
-
-
'Initialize Recordset
-
Set rst = New ADODB.Recordset
-
-
On Error GoTo errhandle
-
-
-
strSq1 = "SELECT DISTINCT activitydesc,materialid FROM activity_table " & _
-
"WHERE activityid in " & _
-
"(Select distinct activityid from sample where(sampledt BETWEEN StartDt AND EndDT)"
-
-
' Get Start Date & End Date
-
-
StartDt = CDate(Format(Range("A4").Value, "dd-MM-yyyy") & " 00:00:00")
-
EndDt = CDate(Format(Range("A4").Value, "dd-MM-yyyy") & " 23:59:59")
-
-
' Re-Connect to Database
-
MakeConnection
-
If Module1.connectSQLSrv(strRegLogin, strRegPwd, strRegDB, strRegServer) Then
-
' Cursor and Lock Characteristic
-
' adOpenDynamic = high Concurrency & Scrollable
-
' adLockOptimistic = other users able to access data
-
' adCmdText = Command Type (Text)
-
-
'Open Recordset
-
rst.Open strSql, sqlConnection, adOpenDynamic, adLockOptimistic, adCmdText
-
-
-
With rst
-
If .RecordCount = 0 Then
-
ComboBox1.Clear
-
ComboBox1.AddItem rst![Request]
-
Do While Not .EOF
-
If Not IsNull(.Fields(0).Value) Then
-
ComboBox1.AddItem (.Fields(0).Value)
-
End If
-
.MoveNext
-
Loop
-
Else
-
Exit Sub
-
End If
-
End With
-
-
Set rst = Nothing
-
-
Else
-
-
'Frm Login activate = asking for user login
-
'MsgBox "Login Failed, please retry!", vbExclamation
-
bolConnected = False
-
Module1.MakeConnection
-
End If
-
-
Exit Sub
-
-
errhandle:
-
MsgBox Err.Number & " : " & Err.Description, vbCritical, "Error!"
-
bolConnected = False<<< Having error on this line
-
If Not sqlConnection Is Nothing Then
-
Set sqlConnection = Nothing
-
End If
-
End Sub
27 3175
May i know why you have posted the code here ?
now what do i understand by that code.... plz specify the problem youre facing
You need to frame the query string dynamically at run time by concatenating the variables. You need to understand when to use quotes "" and when not . Your variables are within quotes try to fix that. Assign value to the variables first and then concatenate to frame the string.
But the error indicated syntax error near the 'in'
strSql = "SELECT DISTINCT activitydesc,materialid FROM Activity" & _
"WHERE activityid in " & _
"(SELECT DISTINCT activityid FROM sample where(sampledt BETWEEN " & startdt & " AND " & enddt & "))"
this is my new coding
Just jumping in here but there is no space between the word Activity and where in your last post (ActivityWhere) which would be an error near the "in" clause...
Good Luck
sorry can explain again cause im really very new in programming
debug.print strSQL...(look at your string concatenation)
Good Luck
you mean the coding in my strSQL is wrong ? if wrong which part i need to edit ???
Two posts up look between the parens...
what is string concatenation ? U mind helping me edit the coding? Thanks in advance
@dennis1989
When you join two strings to form a new one is called string concatenation
Hi
Perhaps this is the problem
"(SELECT DISTINCT activityid FROM sample where sampledt BETWEEN #" & startdt & "# AND #" & enddt & "#)"
You need to delimit the dates with the # sign.
Also you need to cosider the date format, if you computer local date setting is not in American format (mm/dd/yy) then you will need to format the date to American the format to return the correct records.
Just a thought !?
MTB
thanks im trying it out now
By the way what does it means to delimit the date ? I have checked that my local setting of the date is correct
hmm i tried to delimit the date but it still have the same error
Incorrect Syntax near the keyword 'in'
Argh! DENNIS!!!! Build your string, ADD THE DEBUG.PRING strSQL... WHAT DOES IT SAY???? Do you see where there MIGHT BE two words without a SPACE between them!!!????
sorry i will try it now .im really newbie in programming
i got error 3001 when i add debug.print. argument are of the wrong type
Okay, then... use a message box to display the string...(then you can make a screen shot by ALT+PrntScrn)
Good Luck
u mean just show u the strsql string or the entire coding ?
Just the string that you pass...
Here is the code you need instead.
On Error GoTo errhandle
' Get Start Date & End Date
StartDt = CDate(Format(Range("A4").Value, "dd-MM-yyyy") & " 00:00:00")
EndDt = CDate(Format(Range("A4").Value, "dd-MM-yyyy") & " 23:59:59")
strSq1 = "SELECT DISTINCT activitydesc,materialid FROM activity_table " & "WHERE activityid in (Select distinct activityid from sample where(sampledt BETWEEN " & StartDt & " AND " & EndDT &")"
' Re-Connect to Database
The issue is specifically with the variables.
1. You need to give them the right values first, -before- you build the SQL string.
2. You SQL string did not break out the variables from the string properly.
When you pass a SQL string to be executed, it passes the entire string as it computes. If you don't break out your variables properly, in this case, your date range variables, it will choke on them.
In this case, your date range was just the WORDS, StartDt and EndDt, when really you wanted the VALUE of StartDt and EndDt respectively.
Thanks for the help black library but i still have that syntax error at the keyword in "in"
strSql = "SELECT DISTINCT activitydesc,materialid FROM activity_table" & "WHERE activityid in " & _
"(SELECT DISTINCT activityid FROM sample where(sampledt BETWEEN " & startdt & " AND " & enddt & ")
i manage to solve the initial problem with ur coding but my coding is have error 31 on this code :
errhandle:
MsgBox Err.Number & " : " & Err.Description, vbCritical, "Error!"
bolConnected = False
If Not sqlConnection Is Nothing Then
Set sqlConnection = Nothing
End If
End Sub
strSql = "SELECT DISTINCT activitydesc,materialid FROM Activity " & _
"WHERE activityid in " & _
"(SELECT DISTINCT activityid FROM sample where(sampledt BETWEEN " & startdt & " AND " & enddt & ")) " & _
"WHERE sampledt BETWEEN CONVERT(DATETIME, '01/18/2010', 102) AND CONVERT(DATETIME, '01/18/2010 23:59:59', 102))"
I revised my code yet i still have syntax error at keywords 23.
Can someone help me?
Thanks in advance
Display the strSql to a message box and post he screen shot.
Some changes to my project now, instead of using the combobox to display the value, i need to display the value in excel cells. Wonder if anyone can help me with the code on my first post. Thanks in advance
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Alan Murrell |
last post by:
Hello,
One of our web hosting clients is getting the following error when
someone tried to log in form their login page:
--- ODBC ERROR ---
Microsoft OLE DB Provider for ODBC Drivers error...
|
by: ColinWard |
last post by:
Hi. I am trying to run the following code when the user clicks a button,
but I am getting a syntax error in the SQL. I have a feeling it has to
do with brackets. Can anyone help?
here is the...
|
by: Andi Plotsky |
last post by:
Can someone please tell me - what's the problem with the syntax of the
Select portion of the call to the ChangeQueryDef function. My " " marks are
off - but I can't figure out where -
Private...
|
by: priscilla.jenkins |
last post by:
Alright, I'm really new to SQL and VBA and all this, so I might be
completely off course...but just tell me. I know C and Assembly, but
that doesn't help me much here.
I'm trying to create a...
|
by: deko |
last post by:
I'm trying to log error messages and sometimes (no telling when or where)
the message contains a string with double quotes. Is there a way get the
query to insert the string with the double...
|
by: Patrick Olurotimi Ige |
last post by:
why is this giving me error System.Data.SqlClient.SqlException: Line 1:
Incorrect syntax near '='.??
my code is in c#
strSql = "Update addmessage Set message = '"+null+"' Where ID=" +ID;
...
|
by: isaac2004 |
last post by:
hello i am getting a weird al syntax error from my SQL statement
Microsoft OLE DB Provider for ODBC Drivers error '80040e14'
Syntax error (missing
operator) in query expression...
|
by: Mario Krsnic |
last post by:
Hallo zusammen,
I have an app. with SQL-Server. The same page worked fine with Access-DB.
Now I have a problem with this command:
Dim strSQL As String
Dim myConnection As New...
|
by: nerd4access |
last post by:
Hello all! I am not new to access, but new to coding (and posting). I have a database that I have created and need some help with a login form. When a user opens the database, a form pops up...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
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
|
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: 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,...
|
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...
|
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,...
|
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...
| |