Page 1 of 2 12 LastLast
Results 1 to 15 of 20
  1. #1
    cap.zadi is offline Competent Performer
    Windows 7 32bit Access 2010 32bit
    Join Date
    May 2011
    Location
    KSA
    Posts
    481

    Compile Error (Syntax Error)

    Dears



    Any help please?

    Code:
    Private Sub Report_Open(Cancel As Integer)
    
    Dim db As Database
    Dim rs As Recordset
      
      Set db = CurrentDb
      Set rs = db.OpenRecordset("SELECT Min([StartDate]) AS MinOfStartDate "
                    & " FROM QEAVS", dbOpenSnapshot)
      
      If rs.RecordCount > 0 Then
        mdatEarliest = rs!MinOfStartDate
      End If
      
      Set rs = db.OpenRecordset("SELECT Max(IIf(IsDate([EndDate]),CDate([EndDate]),Null)) " _
                    & "AS MaxOfEndDate FROM QEAVS", dbOpenSnapshot)
      
      If rs.RecordCount > 0 Then
        mdatLatest = rs!MaxOfEndDate
      End If
      
      mintDayDiff = DateDiff("d", mdatEarliest, mdatLatest)
     
      Me.txtMinStartDate.Caption = Format(mdatEarliest, "mm/dd/yy")
      Me.txtMaxEndDate.Caption = Format(mdatLatest, "mm/dd/yy")
      
      Set rs = Nothing
      Set db = Nothing
    
    
    End Sub

  2. #2
    andy49's Avatar
    andy49 is offline VIP
    Windows 10 Access 2010 64bit
    Join Date
    Nov 2016
    Location
    London
    Posts
    1,051
    Not sure
    Have you tried closing the first rs before using it again?

    but wondered why not use dmin function instead of first rs.

  3. #3
    cap.zadi is offline Competent Performer
    Windows 7 32bit Access 2010 32bit
    Join Date
    May 2011
    Location
    KSA
    Posts
    481
    Hi

    Thanks for the feedback

    Attached, is the DB which is taken from forum and trying to use the same report format for Employees vacations schedule but having this error only while opening the report.

    regards
    Attached Files Attached Files

  4. #4
    andy49's Avatar
    andy49 is offline VIP
    Windows 10 Access 2010 64bit
    Join Date
    Nov 2016
    Location
    London
    Posts
    1,051
    If you put the Select........... statement in a query, does it return the values you want?
    Attached Thumbnails Attached Thumbnails crop1.png  

  5. #5
    cap.zadi is offline Competent Performer
    Windows 7 32bit Access 2010 32bit
    Join Date
    May 2011
    Location
    KSA
    Posts
    481
    Yeah this is working ok but when a copied into my DB report which is designed for the same way but getting this error.

  6. #6
    andy49's Avatar
    andy49 is offline VIP
    Windows 10 Access 2010 64bit
    Join Date
    Nov 2016
    Location
    London
    Posts
    1,051
    If you put the Select........... statement in a query, does it return the values you want?

    Otherwise without maybe putting your db on here it's really difficult as your code seems ok.

  7. #7
    cap.zadi is offline Competent Performer
    Windows 7 32bit Access 2010 32bit
    Join Date
    May 2011
    Location
    KSA
    Posts
    481
    Dear Sir

    Thanks for your time.

    I was not able to compress the file. So, i made a onedrive link for your review and guidance.

    https://1drv.ms/u/s!AnATXf2TV3fdfK7XBGH5GZN8Wp0

  8. #8
    andy49's Avatar
    andy49 is offline VIP
    Windows 10 Access 2010 64bit
    Join Date
    Nov 2016
    Location
    London
    Posts
    1,051
    Code:
    Private Sub Report_Open(Cancel As Integer)
    
    Dim db As Database
    Dim rs As Recordset
      
      Set db = CurrentDb
      Set rs = db.OpenRecordset("SELECT Min([StartDate]) AS MinOfStartDate " _
                    & " FROM QEAVS", dbOpenSnapshot)
      
      If rs.RecordCount > 0 Then
        mdatEarliest = rs!MinOfStartDate
      End If
      
    Set rs = db.OpenRecordset("SELECT Max(IIf(IsDate([EndDate]),CDate([EndDate]),Null)) " _
                    & "AS MaxOfEndDate FROM QEAVS", dbOpenSnapshot)
      
      If rs.RecordCount > 0 Then
        mdatLatest = rs!MaxOfEndDate
      End If
      
      mintDayDiff = DateDiff("d", mdatEarliest, mdatLatest)
     
      Me.txtMinStartDate.Caption = Format(mdatEarliest, "mm/dd/yy")
      Me.txtMaxEndDate.Caption = Format(mdatLatest, "mm/dd/yy")
      
      Set rs = Nothing
      Set db = Nothing
    
    
    End Sub

    Try the red underscore?

  9. #9
    cap.zadi is offline Competent Performer
    Windows 7 32bit Access 2010 32bit
    Join Date
    May 2011
    Location
    KSA
    Posts
    481
    Sir

    Fantastic and its working.

    Just one more question. How to set up the timeline in 12 months.

    As you can see in my report, the text label shows in months but as this code works starting from min and to max range.

    Any advise please?

  10. #10
    andy49's Avatar
    andy49 is offline VIP
    Windows 10 Access 2010 64bit
    Join Date
    Nov 2016
    Location
    London
    Posts
    1,051
    Do you mean changing the datediff function to "m" instead of "d". This would count months

  11. #11
    cap.zadi is offline Competent Performer
    Windows 7 32bit Access 2010 32bit
    Join Date
    May 2011
    Location
    KSA
    Posts
    481
    No Sir

    I mean, if you see the timeline which is in months as heading and it should start from Jan till Dec not based on minstartdate or maxstartdate.

    This bar shall be based on days as it is already.

  12. #12
    andy49's Avatar
    andy49 is offline VIP
    Windows 10 Access 2010 64bit
    Join Date
    Nov 2016
    Location
    London
    Posts
    1,051
    I'm little unclear.

    Do you mean that you'd like the bars to start at say March if they started in March?

    Please give me an example?

  13. #13
    cap.zadi is offline Competent Performer
    Windows 7 32bit Access 2010 32bit
    Join Date
    May 2011
    Location
    KSA
    Posts
    481
    Well, Sorry i was not able to explain you.

    The time line scale shall be based on current year starting from Jan till dec as now its 2017.

    The status bar shall start and expand (days) based on this scale.

    As report format is attached based on current db but the text scale is shown starting from Jan-Dec.


    Click image for larger version. 

Name:	VacScheduleRpt_Page_1.png 
Views:	17 
Size:	37.5 KB 
ID:	29296

  14. #14
    cap.zadi is offline Competent Performer
    Windows 7 32bit Access 2010 32bit
    Join Date
    May 2011
    Location
    KSA
    Posts
    481
    So, i want to start the timeline from jan to dec not based on system selection from table fields (startdate & enddate)minstartdates or maxenddates as timeline but off course status bar shall grow between actual startdate and enddate as it is now.

  15. #15
    andy49's Avatar
    andy49 is offline VIP
    Windows 10 Access 2010 64bit
    Join Date
    Nov 2016
    Location
    London
    Posts
    1,051
    This seems to be working in print preview?

Page 1 of 2 12 LastLast
Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 3
    Last Post: 01-23-2014, 07:49 AM
  2. Compile Error: Syntax Error in DoCmd.RunSQL Statement
    By Evilferret in forum Programming
    Replies: 1
    Last Post: 08-27-2012, 12:32 PM
  3. Replies: 2
    Last Post: 06-23-2012, 11:59 PM
  4. Replies: 7
    Last Post: 06-08-2012, 09:55 PM
  5. Compile Error Syntax Error
    By Mohamed in forum Access
    Replies: 3
    Last Post: 10-06-2011, 10:12 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums