• Linking MainForm to another form by cmd button

    Home » Forums » AskWoody support » Productivity software by function » MS Access and database help » Linking MainForm to another form by cmd button

    Author
    Topic
    #470683

    I have a main form that has a unique ID and when I click the command button then I would like to open a related form that has ID and populate that field. I have tried to reference main form by putting the control source on the related form to =Forms!FrmMain!ID but this gives me a message saying something about can’t add or delete. Also, I don’t want to make this related form a subform on the main form. What do I need to do to autopopulate the related form ID? Thanks in advance.

    Ben

    Viewing 7 reply threads
    Author
    Replies
    • #1236923

      Ben,

      You need to decide if you are referencing a value in a control on the ‘main form’, or whether you are referencing a value in the forn’s underlying recordsource. Either way will work. Use =Forms!FrmMain!txtID (assuming standard naming convention for the control), or =Forms!FrmMain![ID]. There are other methods, such as passing the ID to the new form as an argument (try the OpenForm wizard for an example, found by adding a new command button to the form). Another way is to store the ID in a global variable.

      Then you should look at what you are doing with the ID value. It would help if we had the full error message, but it sounds as if you are trying to tinker with an Autonumber/seed value instead of filtering on /searching for the number. Have a good look at this area, and if you still see an error make a note of the error number and message. The error message will probably pinpoint the problem.

      Regards,

      Jules

    • #1236956

      Ben,

      Try opening the related form like this:

      DoCmd.OpenForm “frmName”, acNormal ‘, , “ID = ” & lCurID

      Where:
      frmName = the name of your related form.
      ID = the name of your identification field.
      lCurID = a variable holding the value of the ID field you’re looking for.

      May the Forces of good computing be with you!

      RG

      PowerShell & VBA Rule!
      Computer Specs

    • #1236971

      Still not working ..Mainform ID field is autonumber and the related form ID field is Long Integer and both ID fields are named ID.

    • #1236974

      Ben,

      Could you past the code for your command button in a post?

      May the Forces of good computing be with you!

      RG

      PowerShell & VBA Rule!
      Computer Specs

    • #1236976

      Is the form you are opening related data with the same ID, or do you just want to open it to a new record, with the
      ID from the Main Parent form placed into the ID field in the new form, because that is quite a difference

    • #1237146

      It is the same as the main form. I want the ID on the related form to be the same as the id on the main form when I click the command button.

    • #1237150

      Let’s try that again.

      Is the RecordSource of the form you want to open the same RecordSource as the Main Form
      Is the requirement to Open the second form so it is showing the same record.

      Or is the requirement just to populate a field on the second form with the ID that is on the first,
      because they are two quite different objectives.

    • #1237181

      No the record sources are different – they come from 2 different tables where Main form with ID is the primary key and the related form ID field the foreign key. The best way way I can decribe this is for the related form to act like a subform but being accessed by the command button. Thanks

    Viewing 7 reply threads
    Reply To: Linking MainForm to another form by cmd button

    You can use BBCodes to format your content.
    Your account can't use all available BBCodes, they will be stripped before saving.

    Your information: