Results 1 to 4 of 4
  1. #1
    Join Date
    Apr 2003
    Location
    Austin, TX
    Posts
    21

    Unanswered: Problem Adding Record to Form

    In my database (see attached sample MS Access file), there is a form titled Construction Projects (frmConstructionProjects). On that form, there is a command button titled Go To Const Insp Form. When clicked, this button opens another form titled Construction Inspection Form (frmConstInsp). When I type information on this form, the system will add a record to the table titled tblConstInsp (the record source).

    The Key field in table tblConstInsp is ConstInspID (data type is AutoNumber). The field ProjectID is also in this table. In this table, it's data type is Number and the display control on the Lookup tab is Text. The field ProjectID originally comes from the main table in the database which is titled Projects. In this table, ProjectID is the key field with data type as AutoNumber.

    As I said before, when I enter a new record in the form frmConstInsp, all the data I type is being stored in the table tblConstInsp, except the system isn't automatically loading ProjectID. That's why when I close and reopen the form frmConstInsp, the data doesn't reappear. However, if I open the table tblConstInsp and type in the number for ProjectID, then the record does indeed reappear when I reopen frmConstInsp. I have yet to figure out how to make the system automatically load the number for ProjectID.

    Any help in solving this puzzle would be greatly appreciated. Thanks in advance.
    Attached Files Attached Files

  2. #2
    Join Date
    Jan 2007
    Location
    UK
    Posts
    11,434
    Provided Answers: 10
    The forms aren't linked... I suggest you pass the projectID in the openargs of the form open and then access them on formload; perhaps assign it to a hidden bound textbox and that should sort you out!
    George
    Home | Blog

  3. #3
    Join Date
    Apr 2003
    Location
    Austin, TX
    Posts
    21
    I'm just now getting back to this after working on higher priority tasks in my organization for months now. Could you help me understand what you meant when you said "pass the projectID in the openargs of the form open and then access them on formload." Did you mean the "On Open" event procedure? If so, can you help me with the VBA script. Thanks in advance to anyone for help.

  4. #4
    Join Date
    Jan 2007
    Location
    UK
    Posts
    11,434
    Provided Answers: 10
    One of the arguements of the DoCmd.OpenForm action is called OpnArgs* - you can use this to pass a value to the form being opened.

    Then, in the forms on_open event you can access the openargs using
    Code:
    MsgBox Me.OpnArgs
    Which you can then use to folter the forms recordsource.

    Give it a stab and if you're struggling post back what you've tried and we'll take a look


    *OpnArgs or OpenArgs (I can never remember!)
    George
    Home | Blog

Posting Permissions

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