|
code
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Syntax Error - Missing Operator - When Using Date !I have this query to pull the data out from the system. And whenever I run this, I get the "Syntax Error (Missing Operator)" Error displayed. Set conn = New ADODB.Connection FilePath = App.Path & "\Calls.mdb" With conn .Provider = "Microsoft.Jet.OLEDB.4.0" .ConnectionString = "Data Source=" & FilePath & ";" .Open End With 'Set rdset = New ADODB.Recordset 'The following is single string, it just gets wrapped up. Set rdset = conn.Execute("SELECT * FROM InputData Where Name=" & Name.Text & " AND DateNow=#" & Format$(PickDate.List(PickDate.ListIndex), "mm/dd/yyyy") & "#") 'And then I get to use the data here. rdset.Close conn.Close Any help on the above will be greatly appreciated. Thanks & Regards Lovely lovely_angel_for_***@yahoo.com wrote:
> Hi, Try> > I have this query to pull the data out from the system. And whenever I > run this, I get the "Syntax Error (Missing Operator)" Error displayed. > > > 'The following is single string, it just gets wrapped up. > Set rdset = conn.Execute("SELECT * FROM InputData Where Name=" & > Name.Text & " AND DateNow=#" & > Format$(PickDate.List(PickDate.ListIndex), "mm/dd/yyyy") & "#") "SELECT * FROM InputData Where Name='" & Name.Text & "' AND etc You need to wrap string literals in single quotes (') in SQL strings. As a consequence, you also need to double up any single quotes in the string: "SELECT * FROM InputData Where Name='" & Replace(Name.Text, "'", "''") & "' AND A better and neater option is to use parameters - it's all in the docs. -- Larry Lard Replies to group please <lovely_angel_for_***@yahoo.com> wrote in message
news:1143112482.960574.260910@g10g2000cwb.googlegroups.com... Unless your Name column is actually numeric, you'll need to enclose the > Set rdset = conn.Execute("SELECT * FROM InputData Where Name=" & > Name.Text & " AND DateNow=#" & > Format$(PickDate.List(PickDate.ListIndex), "mm/dd/yyyy") & "#") argument you give it in apostrophes: Set rdset = conn.Execute("SELECT * FROM InputData Where Name='" & Name.Text & "' AND DateNow=#" & Format$(PickDate.List(PickDate.ListIndex), "mm/dd/yyyy") & "#") <lovely_angel_for_***@yahoo.com> wrote in message
Show quoteHide quote news:1143112482.960574.260910@g10g2000cwb.googlegroups.com... Try this:> Hi, > > I have this query to pull the data out from the system. And whenever I > run this, I get the "Syntax Error (Missing Operator)" Error displayed. > > > Set conn = New ADODB.Connection > FilePath = App.Path & "\Calls.mdb" > With conn > .Provider = "Microsoft.Jet.OLEDB.4.0" > .ConnectionString = "Data Source=" & FilePath & ";" > .Open > End With > 'Set rdset = New ADODB.Recordset > > > 'The following is single string, it just gets wrapped up. > Set rdset = conn.Execute("SELECT * FROM InputData Where Name=" & > Name.Text & " AND DateNow=#" & > Format$(PickDate.List(PickDate.ListIndex), "mm/dd/yyyy") & "#") > 'And then I get to use the data here. > rdset.Close > conn.Close > > > Any help on the above will be greatly appreciated. > > > Thanks & Regards > Lovely > Set rdset = conn.Execute("SELECT * FROM InputData Where Name='" _ & Replace(Name.Text, "'", "''") & "' AND DateNow=#" _ & Format$(PickDate.List(PickDate.ListIndex), "mm/dd/yyyy") & "#") You need to put single quotes around the text in the SQL statement and the "Replace" function replaces all single quotes in the textbox itself with pairs of single quotes (so the SQL server knows they don't end the string). Cheers, Tony.
AND Operator and Currency data type
Convert HTML to text Error when running vb app with FlexGrid control Vendor ActiveX control Adding treeview programacticlly Obtain MCSE certificaiton without exams(Pay after check results)100% passing gaurantee Refactoring add-in Comparing UDTs ADODB Recordsets into Array Will a P&D packaged DLL (DLLSelfRegister) be registered correctly on all OS's? |
|||||||||||||||||||||||