Results 1 to 9 of 9
  1. #1
    New Lounger
    Join Date
    Jun 2010
    Location
    Atlanta
    Posts
    19
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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

  2. #2
    Star Lounger
    Join Date
    Sep 2002
    Location
    Hastings, Sussex, England
    Posts
    67
    Thanks
    0
    Thanked 1 Time in 1 Post
    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

  3. #3
    Super Moderator RetiredGeek's Avatar
    Join Date
    Mar 2004
    Location
    Manning, South Carolina
    Posts
    9,434
    Thanks
    372
    Thanked 1,457 Times in 1,326 Posts
    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!

    My Systems: Desktop Specs
    Laptop Specs

  4. #4
    New Lounger
    Join Date
    Jun 2010
    Location
    Atlanta
    Posts
    19
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Still not working ..Mainform ID field is autonumber and the related form ID field is Long Integer and both ID fields are named ID.

  5. #5
    Super Moderator RetiredGeek's Avatar
    Join Date
    Mar 2004
    Location
    Manning, South Carolina
    Posts
    9,434
    Thanks
    372
    Thanked 1,457 Times in 1,326 Posts
    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!

    My Systems: Desktop Specs
    Laptop Specs

  6. #6
    5 Star Lounger AndrewKKWalker's Avatar
    Join Date
    Apr 2001
    Location
    Cambridge, UK
    Posts
    1,020
    Thanks
    0
    Thanked 3 Times in 3 Posts
    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
    Andrew

  7. #7
    New Lounger
    Join Date
    Jun 2010
    Location
    Atlanta
    Posts
    19
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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.

  8. #8
    5 Star Lounger AndrewKKWalker's Avatar
    Join Date
    Apr 2001
    Location
    Cambridge, UK
    Posts
    1,020
    Thanks
    0
    Thanked 3 Times in 3 Posts
    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.
    Andrew

  9. #9
    New Lounger
    Join Date
    Jun 2010
    Location
    Atlanta
    Posts
    19
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •