Results 1 to 13 of 13
  1. #1
    system243trd is offline Novice
    Windows 2K Access 2003
    Join Date
    Nov 2011
    Posts
    27

    MS Access 2010 VBA Code for a button to seach a form by date

    I have a form (Form 1)that contains a text box (set as a date picker) and a button.


    I have a second form (Form 2) that contains data including a date field.
    I would like to create some code behind the button on Form 1 so that when the date is selected and the button is pressed then Form 2 will open with the data from the specific date selected in Form1.
    Thanks

  2. #2
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  3. #3
    system243trd is offline Novice
    Windows 2K Access 2003
    Join Date
    Nov 2011
    Posts
    27
    I can't understand why it wont work.
    I have used the following code

    DoCmd.OpenForm "frmMainExercise", , , "Exercise_Date = #" & Me.Text0 & "#"

    The Exercise_Date is the date on the form being opened and the Text0 is the date on the search form. Both fields are set a General date fields. When I select the date from Text0 and then select the button, a new record is displayed rather than finding the record with that date.

  4. #4
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    Is it possible the date field has a time component in it?
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  5. #5
    system243trd is offline Novice
    Windows 2K Access 2003
    Join Date
    Nov 2011
    Posts
    27
    The field within the table is a datetime data type and the format is short date. On the form I have set both fields to short date. Could the date have something to do with this?

  6. #6
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    If the value contains a time it would. Try

    DoCmd.OpenForm "frmMainExercise", , , "DateValue(Exercise_Date) = #" & Me.Text0 & "#"
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  7. #7
    system243trd is offline Novice
    Windows 2K Access 2003
    Join Date
    Nov 2011
    Posts
    27
    Thanks pbaldy I have tried this but it still doesn't work I wonder if there is a problem with Access and not my code :s

  8. #8
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    Can you post the db here?
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  9. #9
    system243trd is offline Novice
    Windows 2K Access 2003
    Join Date
    Nov 2011
    Posts
    27
    I have tried to attach the file but it is too large. &nbsp;It needs to be under 500k and is currently 700k.<br>I have used winrar to try and upload but it does not accept this type of file.<br>Is there any way I can compress the file and attach it?<br><br>

  10. #10
    system243trd is offline Novice
    Windows 2K Access 2003
    Join Date
    Nov 2011
    Posts
    27
    I have tried to attach the file but it is too large. It needs to be under 500k and is currently 700k.<br>
    I have used winrar to try and upload but it does not accept this type of file.<br>
    Is there any way I can compress the file and attach it?<br>
    <br>

  11. #11
    system243trd is offline Novice
    Windows 2K Access 2003
    Join Date
    Nov 2011
    Posts
    27

    Copy of database

    Hi,
    Please find the file attached. The form which contains the code is frmfindexercisedate which opens frmMainexercise.

    Thanks
    Attached Files Attached Files

  12. #12
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    It appears to be working fine. Is any code running for you? The db needs to be in a trusted location, or you have to explicitly enable code.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  13. #13
    system243trd is offline Novice
    Windows 2K Access 2003
    Join Date
    Nov 2011
    Posts
    27
    Yes some of the code is running for me. I think the database is running from a trusted location, I have copied the database to my desktop and enabled the content. On the FormfindExercise when I enter a date into the text box and then select the Search Exercise button, the FrmMainExercise form opens but does not filter the data. This proves that the code is working to some degree. I am using Access 2010 if that has anything to do with the issue?

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

Similar Threads

  1. Access 2010 Form Button Help
    By spartanx117 in forum Forms
    Replies: 1
    Last Post: 11-12-2012, 01:46 PM
  2. HELP>Access 2010 User Login Form Code.
    By zaaimanm in forum Programming
    Replies: 5
    Last Post: 10-22-2012, 07:28 PM
  3. Form Seach Box-all attempts have failed.
    By leamas in forum Forms
    Replies: 12
    Last Post: 06-07-2012, 09:57 AM
  4. Replies: 3
    Last Post: 11-15-2011, 06:29 PM
  5. Seach table from within a form
    By 95DSM in forum Forms
    Replies: 5
    Last Post: 07-12-2010, 09:43 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