Results 1 to 6 of 6
  1. #1
    mgio is offline Novice
    Windows 7 64bit Access 2013
    Join Date
    Jul 2014
    Posts
    13

    Macro to VBA not working?

    Hello I created a Macro to use to open a form with certain parameters but it is not working after being converted to vba and yes event procedure is selected for the event.

    Private Sub Enter_Click()
    On Error GoTo Enter_Click_Err


    DoCmd.SetParameter "StartDate", StartDate
    DoCmd.SetParameter "EndDate", EndDate
    DoCmd.OpenReport "ActivityCde", acViewReport, "", "", acNormal




    Enter_Click_Exit:
    Exit Sub


    Enter_Click_Err:


    MsgBox Error$
    Resume Enter_Click_Exit


    End Sub

  2. #2
    June7's Avatar
    June7 is online now VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,915
    I have never even seen SetParameter method (I don't use macros). http://msdn.microsoft.com/en-us/libr...ffice.15).aspx No idea how it should work with OpenReport method. I would use:

    DoCmd.OpenReport "ActivityCde", acViewReport, , "[datefield] BETWEEN #" & Me.StartDate & "# AND #" & Me.EndDate & "#"
    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
    mgio is offline Novice
    Windows 7 64bit Access 2013
    Join Date
    Jul 2014
    Posts
    13
    got an error expected end of statement and it highlighted the Me in me.enddate. any ideas?

  4. #4
    June7's Avatar
    June7 is online now VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,915
    Sorry, I am missing & in the concatenation. I edited the previous post.

    I am assuming StartDate and EndDate are names of unbound controls for entering filter criteria.
    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
    mgio is offline Novice
    Windows 7 64bit Access 2013
    Join Date
    Jul 2014
    Posts
    13
    That's correct but is there a way I can feed the parameters before opening report

  6. #6
    June7's Avatar
    June7 is online now VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,915
    I assumed you have a form where user enters start and end dates into unbound controls. This code should be behind that form. User inputs parameters and clicks a button to open report. Additional code can verify both dates provided and only open report if that is the case.
    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.

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

Similar Threads

  1. Converted macro to VBA not working
    By gemadan96 in forum Forms
    Replies: 5
    Last Post: 06-04-2014, 10:36 AM
  2. Data Macro's not working... please help
    By MFriend in forum Access
    Replies: 4
    Last Post: 06-02-2014, 03:00 PM
  3. Replies: 7
    Last Post: 08-10-2012, 03:09 PM
  4. Macro Filter not working....
    By avarusbrightfyre in forum Access
    Replies: 2
    Last Post: 06-18-2011, 04:09 PM
  5. RunCode in macro not working
    By LilMissAttack in forum Access
    Replies: 0
    Last Post: 05-27-2010, 05:01 PM

Tags for this Thread

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