Results 1 to 8 of 8
  1. #1
    Khalil Handal is offline Competent Performer
    Windows 10 Access 2003
    Join Date
    Jun 2016
    Posts
    237

    Refresh a form using VBA code

    Hi,


    I have a form Form1 that shows several records. Double click on the record opens form2 to show details for that specific record.
    I have a cmdMarkDeleted on form2. If the user clicks on the cmdMarkDeleted the record is marked as deleted record, Form2 closes and I am back to Form1. This record that is marked as deleted should not be shown on Form1. So I have to press the F5 key to refresh Form1.

    Can I do this programmatically to refresh Form1 without having to press the F5 key?

    Any help is appreciated
    Khalil

  2. #2
    Bob Fitz's Avatar
    Bob Fitz is offline Access Developer
    Windows 10 Access 2016
    Join Date
    May 2011
    Location
    Essex UK
    Posts
    3,535
    I think you may need to Requery rather than Refresh. Try:

    Forms!Form1.Requery
    If this helped, please click the star at the bottom left of this posting and add to my reputation . Many thanks.
    Bob Fitzpatrick

  3. #3
    Join Date
    May 2018
    Location
    Living in Scotland UK
    Posts
    1,563
    Hi Khalil

    You should Close Form1 when you Open Form2 using something like this:-

    DoCmd.Close , ""
    DoCmd.Close acForm, "Form1"
    DoCmd.OpenForm "Form2", acNormal, "", "", , acNormal

    Then on the Close of Form2 open Form1

  4. #4
    Bob Fitz's Avatar
    Bob Fitz is offline Access Developer
    Windows 10 Access 2016
    Join Date
    May 2011
    Location
    Essex UK
    Posts
    3,535
    Quote Originally Posted by mike60smart View Post
    Hi Khalil

    You should Close Form1 when you Open Form2 using something like this:-

    DoCmd.Close , ""
    DoCmd.Close acForm, "Form1"
    DoCmd.OpenForm "Form2", acNormal, "", "", , acNormal

    Then on the Close of Form2 open Form1
    While that would solve the OP's original problem it won't help if the user needs to look a records on form1 while form2 is open.
    If this helped, please click the star at the bottom left of this posting and add to my reputation . Many thanks.
    Bob Fitzpatrick

  5. #5
    Khalil Handal is offline Competent Performer
    Windows 10 Access 2003
    Join Date
    Jun 2016
    Posts
    237
    Hi,
    I tried the requery option first and it works fine.
    I will try closing the forms and reopening them and see how it works.

    I was wondering the difference between: (Requery and Refresh) since they both gave the same result.

    Thanks for both of you.

  6. #6
    Bob Fitz's Avatar
    Bob Fitz is offline Access Developer
    Windows 10 Access 2016
    Join Date
    May 2011
    Location
    Essex UK
    Posts
    3,535
    Quote Originally Posted by Khalil Handal View Post
    Hi,
    I tried the requery option first and it works fine.
    I will try closing the forms and reopening them and see how it works.

    I was wondering the difference between: (Requery and Refresh) since they both gave the same result.

    Thanks for both of you.
    Glad you have it working. If Refresh works for you then stick with that. See link for differences: https://www.599cd.com/tips/access/re...ted%20records.

    I would advise against the closing and reopening of the original form.
    If this helped, please click the star at the bottom left of this posting and add to my reputation . Many thanks.
    Bob Fitzpatrick

  7. #7
    Join Date
    May 2018
    Location
    Living in Scotland UK
    Posts
    1,563
    Hi Bob

    I agree but I also wonder why there is a need to open Form2 at all?

    Surely if there is a Control for MarkingAsDeleted which would I assume be a YesNo Checkbox, why not just select Yes on Form1. Then there is no need to open Form2?

  8. #8
    Bob Fitz's Avatar
    Bob Fitz is offline Access Developer
    Windows 10 Access 2016
    Join Date
    May 2011
    Location
    Essex UK
    Posts
    3,535
    Quote Originally Posted by mike60smart View Post
    Hi Bob

    I agree but I also wonder why there is a need to open Form2 at all?

    Surely if there is a Control for MarkingAsDeleted which would I assume be a YesNo Checkbox, why not just select Yes on Form1. Then there is no need to open Form2?
    We would need to OP to answer that one but perhaps the second form would be needed to reinstate a deleted record.
    If this helped, please click the star at the bottom left of this posting and add to my reputation . Many thanks.
    Bob Fitzpatrick

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

Similar Threads

  1. Code for clearing a form after refresh
    By Marcia in forum Macros
    Replies: 3
    Last Post: 08-27-2019, 08:20 AM
  2. Refresh a table using code
    By john134 in forum Programming
    Replies: 2
    Last Post: 01-22-2014, 07:04 PM
  3. how to give a code for save and refresh
    By venu_resoju in forum Forms
    Replies: 7
    Last Post: 04-03-2013, 12:29 PM
  4. Form Code refresh on open
    By mseeker22 in forum Forms
    Replies: 2
    Last Post: 07-08-2011, 12:35 AM
  5. Replies: 3
    Last Post: 10-04-2010, 01:31 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