Results 1 to 6 of 6
  1. #1
    Join Date
    Apr 2007
    Posts
    45

    Unanswered: Subform StLink Criteria and Add New Record command button

    I have a main form that is for a piece of equipment (equip # is primary key for table). On this main form there is a subtable that summarizes all work orders that have been opened for that piece of equip ID. I have a command button on this frmEquipment that will retrieve the frmRepairWorkOrder and have set up the system through the frmRepairWorkOrders "On Activate" so that if you select the Repair Work Order ID (GSRID) from the subtable, it will bring up all the repair work orders associated with the equipID, but the specific Repair Work Order (GSRID) that you want to view is the one it directly takes you to (with the others filtered behind it.) The code for the On Activate is as follows:

    Private Sub Form_Activate()
    On Error GoTo Err_Form_Activate

    If Forms![frmEquipment]![fsubWorkOrderbyEquipment].Form.RecordsetClone.RecordCount > 0 Then
    DoCmd.GoToControl "GSRID"
    DoCmd.FindRecord Forms![frmEquipment]![fsubWorkOrderbyEquipment].Form![GSRID]
    End If


    Exit_Form_Activate:
    Exit Sub

    Err_Form_Activate:
    MsgBox Err.Description
    Resume Exit_Form_Activate
    End Sub

    Here is the problem. This works beautifully until the following scenario: When you want to add a new work order and add a blank record (I have a command button that opens a new blank record),1 of two things will happen when you are putting info in for new record:

    1. It will just randomly switch between the new record you are inputting to the record that was selected on the frmEquipment.
    2. When you go to print the new record you created (command button that prints a report), the report will come out blank. You have to exit out of frmRepairWorkOrder, enter the equipment number in for frmEquipment so that the subtable updates with the new order you entered, select the new order you entered, open frmRepairWorkOrder, and now when you print order the order, it prints it with the information.

    Is there a way to program the command button that creates a new record that will tell frmRepairWorkOrder to ignore the selected work order in the subtable of frmEquipment so that this doesn't happen?

    Database is attached
    Attached Files Attached Files

  2. #2
    Join Date
    Jan 2007
    Location
    UK
    Posts
    11,434
    Provided Answers: 10
    Create a button using the wizard; I believe there's an option for go to new record.
    George
    Home | Blog

  3. #3
    Join Date
    Apr 2007
    Posts
    45
    I did-I created the button using the wizard to create a new record. And the button works. However, the problem is I think in the "On Activate" programming for this form - since it instructs the form to look to the subtable for what record it should be on. So when you are putting in a new record, it will do one of two things:
    1. Randomly switch to the record that is selected in the subtable on frmEquipment.
    2. Or when you go to print report - it prints up blank.

    There should be a way to program the command button to add a new work order that tells it to ignore the on-activate programming for frmRepairWorkOrder, no? Unfortunately, my VBA skills suck, so I don't know how to programm the command button to disregard the on-activate language for the form.

  4. #4
    Join Date
    Jan 2007
    Location
    UK
    Posts
    11,434
    Provided Answers: 10
    Can you post the code for the on activate event please? Give us a quick explanation of what it's doing.
    George
    Home | Blog

  5. #5
    Join Date
    Apr 2007
    Posts
    45
    The code for the on-activate is in my original post. And the purpose of this code is to direct the form to open up to the work order that is selected in the subtable of frmEquipment (when there are 20 plus work orders for a piece of equipment - you don't want to have to scroll through all of them to find the particular one that you want.)

    My database is also attached if you want to see how everything is put together.

  6. #6
    Join Date
    Jan 2007
    Location
    UK
    Posts
    11,434
    Provided Answers: 10
    I think you should move your activate code to the on click event of opening button.
    Code:
    DoCmd.OpenForm "<FormName>", , , "<WhereCondition>"
    Alternatively you can pass a value in the OpenArgs of the form and test this value on activate; i.e.
    Code:
    DoCmd.OpenForm "<FormName>", , , , , , "New Record"
    Code:
    If Me.OpenArgs <> "New Record" Then
        If Forms![frmEquipment]![fsubWorkOrderbyEquipment].Form.RecordsetClone.RecordCount > 0 Then
            DoCmd.GoToControl "GSRID"
            DoCmd.FindRecord Forms![frmEquipment]![fsubWorkOrderbyEquipment].Form![GSRID]
        End If
    Else
        <code for go to new record>
    End If
    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
  •