Open frm in Add mode

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Nour469
    New Member
    • Oct 2008
    • 18

    Open frm in Add mode

    Hello,
    I need simple help!
    I have a form with a field (DrsName) which is a combo box that looks up values in another table (Drs List). When I come across a name that is not in the list, I need to open the form (Drs List) and add the name. for which I added a cute button. I am having 2 problems:
    1) I cannot get the button to open the form in add mode, as I don't want the users to accidently type over the data, I just want to be able to ADD a new name. or at least open the form in data sheet view! I am able to do it in the switchboard but not within my form!
    2) when I add the name and come back to my form, the list is not updated until I close the form and re-open it again. which is a problem as I need to find the patient I was working on and choose the name from the list and continue entering the data.

    I am sure there is a simple way to do this... I just can't figure it out!

    Thanks for the help.
    Nour
  • DonRayner
    Recognized Expert Contributor
    • Sep 2008
    • 489

    #2
    To open your form in add mode you need to use the following code, replace FormName with the name of your form.

    Code:
    DoCmd.OpenForm "FormName", , , , acFormAdd
    To have the combobox updated after you add a new item add the following to the close event of your new form. Replace MyForm with the name of your form and MyCombobox with the name of your combobox

    Code:
    Forms!MyForm!MyCombobox.requery

    Comment

    • Nour469
      New Member
      • Oct 2008
      • 18

      #3
      Hi,
      Thanks for your reply, The first one worked like magic and my form opens in Add mode, But the second one did not work, it keeps giving my errors, not accepting form name...

      Comment

      • DonRayner
        Recognized Expert Contributor
        • Sep 2008
        • 489

        #4
        Originally posted by Nour469
        Hi,
        Thanks for your reply, The first one worked like magic and my form opens in Add mode, But the second one did not work, it keeps giving my errors, not accepting form name...
        It should work. Please post back the exact text from the error that you are getting.

        Comment

        • Nour469
          New Member
          • Oct 2008
          • 18

          #5
          Hi Donrayner,

          The name of my form was Referring Drs list and it was highlighting the "Drs: in yello but I changed it to: ReferringDrsLis t which is now fine. the name of my combo box is: referringDr. Now the combo box is is the "Main Form"

          I am opening the form: ReferringDrsLis t and on close I am typing in the code builder:

          Forms!Referring DrsList!Referri ngDr.requery

          and now I am getting the Run-Time error '2465' can't find the field "ReferringD r"
          (The combo box is in the main form, and I have a button whithin the main form to open the form "ReferringDrsLi st" .....

          What am I doing wrong!?
          Nour

          Comment

          Working...