Results 1 to 13 of 13
  1. #1
    Aloupha is offline Novice
    Windows XP Access 2003
    Join Date
    Nov 2009
    Posts
    26

    [Event Procedure] to edit a record

    Hello,



    I am trying to use [Event Procedure] to allow users to edit a specific record. I want to click on "Edit Record" and prompted to enter a date to pull the record. I can accomplish this using a combination of queries and macros. However, I am new to using [Event Procedure] and I am thinking I could accomplish the same thing using it.

    I have read that I could use DoCmd.OpenForm, and I am having issues with the correct way to write the [WhereCondition]

    Code:
    Private Sub EditRecord_Click()
        DoCmd.OpenForm Updates,acNormal,,[WhereCondition],acFormEdit,acWindowNormal,,
    End Sub
    How would I go about doing that?

    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
    It looks like this:

    http://www.baldyweb.com/wherecondition.htm

    you could use an InputBox to prompt the user instead of the form reference, but I wouldn't.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  3. #3
    Aloupha is offline Novice
    Windows XP Access 2003
    Join Date
    Nov 2009
    Posts
    26
    Quote Originally Posted by pbaldy View Post
    It looks like this:

    http://www.baldyweb.com/wherecondition.htm

    you could use an InputBox to prompt the user instead of the form reference, but I wouldn't.
    Thanks, I am still not sure how to get it done. I think I came accross that link before and wasn't able to figure it out.

    Code:
    Private Sub EditRecord_Click()
        DoCmd.OpenForm "Updates", , , "Date = #" &DateT& "#"
    End Sub
    This is what I have. At first nothing happened. I closed everything and opened it back up. I get the following error:

    Run-time error '3075':

    Syntax Error in date in query expression '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
    The error would imply that DateT (a variable?) is empty.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  5. #5
    Aloupha is offline Novice
    Windows XP Access 2003
    Join Date
    Nov 2009
    Posts
    26
    Please bear with me. What should I have in the Me.Controlname? I DateT is the name of the Testbox for the Date field of the form.

  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
    Then

    Me.DateT
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  7. #7
    Aloupha is offline Novice
    Windows XP Access 2003
    Join Date
    Nov 2009
    Posts
    26
    Quote Originally Posted by pbaldy View Post
    Then

    Me.DateT
    I did that and the error remains. I see two behaviors.

    1) On the switchboard, I have an event procedure that opens the form as acFormAdd (DoCmd.OpenForm " Updates", , , , acFormAdd)

    2) On the form itself, there are three link options: 1) Add Record, 2) Edit Record, 3) View Records.

    When I open the form through the switchboard as AcFormAdd and click on the Edit Record link, I still get the error "Run-time error '3075':

    Syntax Error in date in query expression 'Date= ##'"

    When I am viewing records and I click on the "Edit Record" option, nothing seems to happen. However, I noticed that only 23 records out of 500+ records are showing and all of the 23 records are from the same date. So, it looks like it's kind of working in this place working but it does not prompt me to enter the date. It just does the filter by itself. How? I don't know.

    I am not sure why I get different results when I click on the Edit Record button from viewing the form as acFormAdd vs. Normal view (DoCmd.OpenForm "Updates")

  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
    Aloupha is offline Novice
    Windows XP Access 2003
    Join Date
    Nov 2009
    Posts
    26
    Not really, it's a department db of a company.

  10. #10
    Aloupha is offline Novice
    Windows XP Access 2003
    Join Date
    Nov 2009
    Posts
    26
    Quote Originally Posted by Aloupha View Post
    Not really, it's a department db of a company.
    Okay, attached is mock-up version of the db. It functions exactly the same with the same behaviors.
    Attached Files Attached Files

  11. #11
    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 I click on the button on the main form, type a date into the date box on the second and click on Edit, it brings up the record for that date.

    I don't think I would open the same form from within itself, and the fact that the textbox you're typing a date into to find is also bound to the table is going to cause you problems.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  12. #12
    Aloupha is offline Novice
    Windows XP Access 2003
    Join Date
    Nov 2009
    Posts
    26
    What is the proper way to do it? All I want to do is make it possible to edit a record using the date as a folder. The user will enter the date to be edited. I can do it with using a query and a macro. I wanted to avoid doing it that way.

  13. #13
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    Since the form is bound to the table, you can use the combo box wizard, using the "Find a record..." option. That will give you a combo that will jump to the chosen record. As it is, since that textbox is bound, when you type in a date to find, you're either changing the value of the displayed record or adding a new one.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

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

Similar Threads

  1. Replies: 3
    Last Post: 05-07-2012, 12:17 PM
  2. Replies: 5
    Last Post: 10-26-2011, 02:59 PM
  3. 'After update' Event procedure
    By sk88 in forum Access
    Replies: 5
    Last Post: 08-30-2011, 02:51 PM
  4. On-Click Event Procedure
    By tbassngal in forum Forms
    Replies: 6
    Last Post: 07-20-2011, 07:06 AM
  5. On Click Event Procedure
    By MrDean in forum Forms
    Replies: 3
    Last Post: 10-07-2009, 07:16 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