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

Date Retrieving Error

Hi Everyone,
I am using Access 2003 to input 2 dates from text boxes to display a report. The following is the code I'm trying to run:

Expand|Select|Wrap|Line Numbers
  1.  
  2. Dim fromDate As Date
  3.     Dim toDate As Date
  4.     Dim BusProgIDs As String
  5.     Dim IncAllOpen As Boolean
  6.     Dim strWhere As String
  7.     Dim ctl As control
  8.     Dim i As Integer
  9.  
  10.     If ckAllOpen.Value = True Then
  11.         IncAllOpen = True
  12.     Else
  13.         IncAllOpen = False
  14.     End If
  15.  
  16.    If lstBusinessProgramsPF.ListIndex > 0 Then
  17.  
  18.         Set ctl = lstBusinessProgramsPF
  19.  
  20.         fromDate = Format(txtFromProdFail.Value, "mm/dd/yyyy")
  21.         toDate = Format(txtToProdDate.Value, "mm/dd/yyyy")
  22.         BusProgIDs = GetSqlBusinessProgram(ctl)
  23.  
  24.         strWhere = ""
  25.         strWhere = strWhere & BusProgIDs
  26.         strWhere = strWhere & " AND CAConfirmationDate BETWEEN #" & fromDate & "# AND #" & toDate & "#"
  27.         If IncAllOpen = True Then
  28.             strWhere = strWhere & " OR (" & BusProgIDs
  29.  
  30.             strWhere = strWhere & " AND (CAConfirmationDate Is NULL)"
  31.             strWhere = strWhere & " AND (OpeningDate <= #" & toDate & "#))"
  32.         End If
  33.  
  34.         DoCmd.OpenReport "ProgressReport", acViewPreview, , strWhere, , (fromDate & "," & toDate)
  35.     Else
  36.         MsgBox "One or more Business Programs must be selected to view a report.", vbOKOnly
  37.     End If
  38.  
However, when I attempt to run it it gives me this error:
syntax error(missing operator) in query expression '(AND CAConfirmationDate BETWEEN #12/12/2000# AND #12/12/2005

Anyone have any idea what would work? Thanks
-Todd
Feb 27 '07 #1
8 1546
MMcCarthy
14,534 Expert Mod 8TB
Hi Todd

What is this function doing..
Expand|Select|Wrap|Line Numbers
  1. BusProgIDs = GetSqlBusinessProgram(ctl)
Feb 27 '07 #2
Hi Todd

What is this function doing..
Expand|Select|Wrap|Line Numbers
  1. BusProgIDs = GetSqlBusinessProgram(ctl)
This function searches through a list box in order to place each ID of each record into the report.
Feb 27 '07 #3
MMcCarthy
14,534 Expert Mod 8TB
This function searches through a list box in order to place each ID of each record into the report.
But it's adding it to the where criteria in the code.
Feb 27 '07 #4
But it's adding it to the where criteria in the code.
It places the control from the list box into the seperate function
Expand|Select|Wrap|Line Numbers
  1. Private Function GetSqlBusinessProgram(lstControl As control) As String
  2.     On Error GoTo GetSqlBusinessProgramError
  3.  
  4.     Dim sqlBP As String
  5.     Dim i As Integer
  6.  
  7.     For i = 0 To lstControl.Items.Count - 1
  8.         If Len(sqlBP) > 0 Then
  9.             sqlBP = sqlBP & ","
  10.         End If
  11.         sqlBP = sqlBP & lstControl.ItemData(lstControl.Items(i))
  12.     Next
  13.     sqlBP = "BusinessProgramID IN(" & sqlBP & ")"
  14.     GetSqlBusinessProgram = sqlBP
  15.  
  16. ExitSqlBusinessPrograms:
  17.     Exit Function
  18.  
  19. GetSqlBusinessProgramError:
  20.     MsgBox Err.Description, vbOKOnly
  21.     Err.Clear
  22.     Resume ExitSqlBusinessPrograms
  23.  
  24. End Function
Feb 27 '07 #5
MMcCarthy
14,534 Expert Mod 8TB
OK it looks like the problem is in the use of brackets. Try this ...

Expand|Select|Wrap|Line Numbers
  1.  
  2. Dim fromDate As Date
  3.     Dim toDate As Date
  4.     Dim BusProgIDs As String
  5.     Dim IncAllOpen As Boolean
  6.     Dim strWhere As String
  7.     Dim ctl As control
  8.     Dim i As Integer
  9.  
  10.     If ckAllOpen.Value = True Then
  11.         IncAllOpen = True
  12.     Else
  13.         IncAllOpen = False
  14.     End If
  15.  
  16.    If lstBusinessProgramsPF.ListIndex > 0 Then
  17.  
  18.         Set ctl = lstBusinessProgramsPF
  19.  
  20.         fromDate = Format(txtFromProdFail.Value, "mm/dd/yyyy")
  21.         toDate = Format(txtToProdDate.Value, "mm/dd/yyyy")
  22.         BusProgIDs = GetSqlBusinessProgram(ctl)
  23.  
  24.         strWhere = "("
  25.         strWhere = strWhere & BusProgIDs
  26.         strWhere = strWhere & " AND (CAConfirmationDate BETWEEN #" & fromDate & "# AND #" & toDate & "#))"
  27.         If IncAllOpen = True Then
  28.             strWhere = strWhere & " OR (" & BusProgIDs
  29.  
  30.             strWhere = strWhere & " AND (CAConfirmationDate Is NULL)"
  31.             strWhere = strWhere & " AND (OpeningDate <= #" & toDate & "#))"
  32.         End If
  33.  
  34.         DoCmd.OpenReport "ProgressReport", acViewPreview, , strWhere, , (fromDate & "," & toDate)
  35.     Else
  36.         MsgBox "One or more Business Programs must be selected to view a report.", vbOKOnly
  37.     End If
  38.  
Mary
Feb 27 '07 #6
OK it looks like the problem is in the use of brackets. Try this ...

Expand|Select|Wrap|Line Numbers
  1.  
  2. Dim fromDate As Date
  3.     Dim toDate As Date
  4.     Dim BusProgIDs As String
  5.     Dim IncAllOpen As Boolean
  6.     Dim strWhere As String
  7.     Dim ctl As control
  8.     Dim i As Integer
  9.  
  10.     If ckAllOpen.Value = True Then
  11.         IncAllOpen = True
  12.     Else
  13.         IncAllOpen = False
  14.     End If
  15.  
  16.    If lstBusinessProgramsPF.ListIndex > 0 Then
  17.  
  18.         Set ctl = lstBusinessProgramsPF
  19.  
  20.         fromDate = Format(txtFromProdFail.Value, "mm/dd/yyyy")
  21.         toDate = Format(txtToProdDate.Value, "mm/dd/yyyy")
  22.         BusProgIDs = GetSqlBusinessProgram(ctl)
  23.  
  24.         strWhere = "("
  25.         strWhere = strWhere & BusProgIDs
  26.         strWhere = strWhere & " AND (CAConfirmationDate BETWEEN #" & fromDate & "# AND #" & toDate & "#))"
  27.         If IncAllOpen = True Then
  28.             strWhere = strWhere & " OR (" & BusProgIDs
  29.  
  30.             strWhere = strWhere & " AND (CAConfirmationDate Is NULL)"
  31.             strWhere = strWhere & " AND (OpeningDate <= #" & toDate & "#))"
  32.         End If
  33.  
  34.         DoCmd.OpenReport "ProgressReport", acViewPreview, , strWhere, , (fromDate & "," & toDate)
  35.     Else
  36.         MsgBox "One or more Business Programs must be selected to view a report.", vbOKOnly
  37.     End If
  38.  
Mary
Hi Mary,
It gace me the same error. I think my problem is with the function that this function calls, the GetsqlBusinessProgram maybe?
Feb 27 '07 #7
MMcCarthy
14,534 Expert Mod 8TB
Hi Mary,
It gace me the same error. I think my problem is with the function that this function calls, the GetsqlBusinessProgram maybe?
You need to see what's actually in the criteria.

Put
Expand|Select|Wrap|Line Numbers
  1. Debug.Print strWhere
before the open report command and open the immediate window to see what's being printed

Then copy and paste it here.

Mary
Feb 27 '07 #8
NeoPa
32,556 Expert Mod 16PB
Don't forget to use Copy / Paste Todd.
Your first post was obviously not done using the clipboard (there were typos in it) so it was devoid of most of its information.
Mar 2 '07 #9

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

Similar topics

2
by: Sakke | last post by:
Hello! We have written a GCryptoSvr.dll COM server in C++. Inside that resides WebClient COM component. WebClient CLSID is {8DC27D48-F94C-434B-A509-C3E1A3E75B9E}. When we are using that...
1
by: jimmyfo | last post by:
Hi, I recently wrote an ASP.Net web application in VS2005 and published (using VS2005 Publish feature) it to a relatively clean machine with ASP.Net 2.0 and MDAC 2.8 installed on it. However, when...
4
by: tito | last post by:
In my program i am trying to retrieve 'date' field from an excel sheet .This data is inserted into a My SQL Database.The default format for 'date ' field for Excel sheet is in the form of...
1
by: stuck1512 | last post by:
hi, i was writing an apache module & successful in retrieving archived files from a folder. i compared all file properties before retrieving but the problem is now i have to retrieve them as...
30
by: fniles | last post by:
On my machine in the office I change the computer setting to English (UK) so the date format is dd/mm/yyyy instead of mm/dd/yyyy for US. This problem happens in either Access or SQL Server. In the...
9
by: Martin | last post by:
I'm retrieving some records from a database. One of the fields contains a date/time. I would like to format it as I send it out to the table in the displayed page. Can some one please tell me...
6
by: Geoff Cox | last post by:
Hello, at the moment I can add the combined date and time into MySQL using php $dt1 = date("Y-m-d H:i:s"); is it possible to add the date and time separately? I thought it might be
3
by: teo | last post by:
I'm developing a software (a WinApp, not a WebApp) to retrieve Date & Time from a web server, but firstly I need to to test it on my PC, with "localhost" I'm using the VB Net language (below...
3
by: Bruno Vignola | last post by:
Good Morning all, I need to interoperate with the Calendar of MS Outlook 2003 (inserting, retrieving, listing events, etc. etc.) from an ASP.NET application; I first developed a simple windows...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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
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...
0
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...

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.