Results 1 to 5 of 5
  1. #1
    libraccess's Avatar
    libraccess is offline Competent Performer
    Windows 7 32bit Access 2010 32bit
    Join Date
    Mar 2012
    Location
    Napier New Zealand
    Posts
    129

    wading in a swamp of VBA

    I am trying to use the code from Allen Browne where Dates are handled whether or not in dd/mm/yy or mm/dd/yy

    to open a report and list entries where a date field is less than 2 months away
    I have
    DoCmd.OpenReport "rptCerts", acViewReport, , "[CertDateExp] < #" & DateAdd("m", 2, Date) & "#"
    which is fine but not in this part of the world as today being 2/3 becomes 2/5 in two months which 5th Feb elsewhere

    code below is me just mucking about to no useful effect
    Private Sub btnCertsExp_Click()
    Dim strWhere As String
    Dim strDateField As String


    Const strcJetDate = "\#mm\/dd\/yyyy\#"
    'Set Date for all before two months from now
    strDateField = CertDateExp
    strWhere = "(" & strDateField & " >= " & Format("#" & DateAdd("m", 2, Date) & "#", strcJetDate) & ")"


    DoCmd.OpenReport "rptCerts", acViewReport, , strWhere
    End Sub
    Thanks

  2. #2
    June7's Avatar
    June7 is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,771
    Why no useful effect? What is wrong - error message, wrong results, nothing happens?
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  3. #3
    libraccess's Avatar
    libraccess is offline Competent Performer
    Windows 7 32bit Access 2010 32bit
    Join Date
    Mar 2012
    Location
    Napier New Zealand
    Posts
    129
    Hi yes sorry after trying to play with this code which I don't really understand I didn't give a good question.
    When I did this a week ago the dates were 2*/2 which is unambiguous. but of course now 02/03 is. however
    RT error 3075
    Syntax error missing operator ..... '(#3/05/2013#)'

    The original code which you probably know of is (partly)
    'Purpose: Filter a report to a date range.
    'Documentation: http://allenbrowne.com/casu-08.html

    If IsDate(Me.txtStartDate) Then
    strWhere = "(" & strDateField & " >= " & Format(Me.txtStartDate, strcJetDate) & ")"
    End If
    If IsDate(Me.txtEndDate) Then
    If strWhere <> vbNullString Then
    strWhere = strWhere & " AND "
    End If
    strWhere = strWhere & "(" & strDateField & " < " & Format(Me.txtEndDate + 1, strcJetDate) & ")"
    End If

  4. #4
    June7's Avatar
    June7 is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,771
    I can't get code to work. It errors on the last strWhere because of the +1. Gives me datatype mismatch message.

    I also don't understand how this is supposed to deal with the mmddyyyy vs ddmmyyyy structure.

    I enter StartDate of 3/2/2012 {for 3 Feb} but the constructed string is: #3/02/2012# {for Mar 2}, not #2/03/2012# {for Feb 3}

    If the data in the field is ddmmyyyy I still don't understand how formatting the criteria as mmddyyyy helps.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  5. #5
    libraccess's Avatar
    libraccess is offline Competent Performer
    Windows 7 32bit Access 2010 32bit
    Join Date
    Mar 2012
    Location
    Napier New Zealand
    Posts
    129
    I don't understand it either but the full set of code by Allen Browne is one of the most useful (and most often used) bits of code where a start and end date is entered and could be used on US or Euro Date format machines.
    I think I'll just have to go with 2 identical reports one with the query criteria <DateAdd("m",2,Date().
    It works and i guess it is not so clumsy

    Thanks for your reply anyway

Please reply to this thread with any new information or opinions.

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