Apply filter when opening form

coolcatkelso

Registered User.
Local time
Today, 10:08
Joined
Jan 5, 2009
Messages
279
Hiya

I have my main form (Workorders by Customer) with a subform (Workorders by Customers Subform)

The subform is Datasheet style, In there is the Workorder ID taken from (Workorders) If you click on the workorder id in the subform, It should open up Schedule

The form Schedule has the following IDs

SchedID AutoNumber
WorkorderID Number
CustomerID Number

I'm trying to get it so when I click on the Subform workorderID, it opens up the schedule form and displays the information relating to that workorder.. But if there is no current record, then I want it to make one

Currently, if I click on the WorkorderID it is just showing as being filtered, but showing the same record for all

I have setup a Relationship based on WorkorderID

I am using a VBA to open the form. On the Main form with the subform etc on it, I have -

Docmd.OpenForm "Schedule",,,,acForm,,Me.WorkorderID

and on the actual Schedule form I have this set On Open

If Me.NewRecord Then
If Not IsNull(Me.OpenArgs) Then
Me.WorkorderID = Me.OpenArgs
End If
End If

Using the VBa script, I get the form to open but it won't filter out the WorkorderID.. Still showing same record for all

What am I missing?

Access 2007

Just an update

If I enter the workorderID into the Schedule page manually, it stores the information correctly.. Current setup is this - =[Forms]![Workorders by Customer]![Workorders by Customer Subform].[Form]![WorkorderID]

I'm using that to get the Schedule to lookup the workorderID from the Subform I click on. It is saving the info into the table for Schedule, but when I click to open it again, its like its adding a new record all the time?

But if I take the out and enter the ID myself, everything is fine??
________
IPAD ACCESSORIES
 
Last edited:
Here's an example to do that. In the form to be opened:
Code:
Private Sub Form_Load()
  If Len(Nz(Me.OpenArgs, "")) > 0 Then
    RecordID.SetFocus
    DoCmd.FindRecord Me.OpenArgs
    If Me.RecordID <> Me.OpenArgs Then
     DoCmd.GoToRecord , , acNewRec
     Me.RecordID = Me.OpenArgs
    End If
  End If
End Sub

The above code assumes that RercordID is defined as Text Datatype, as it should be. Only "numbers" to used in math calculations should be defined as numerical. But if you do have the connecting field defined as a number, you have to modify the code slightly, to:

Code:
Private Sub Form_Load()
  If Len(Nz(Me.OpenArgs, "")) > 0 Then
    RecordID.SetFocus
    DoCmd.FindRecord Me.OpenArgs
    If Me.RecordID <> [B]Val(Me.OpenArgs)[/B] Then
     DoCmd.GoToRecord , , acNewRec
     Me.RecordID = Me.OpenArgs
    End If
  End If
End Sub

because Access converts OpenArgs to a string.
 
Your code is *only* looking at the OpenArgs when the form opens on a New Record. It sounds like you want to use the WhereCondition argument rather than the OpenArgs argument. Either that or do a .FindFirst in the OnLoad event of the next form and if not found the start a new record. You could also do a DCount() in the first form and if 0 then open the next form in Add mode.
 

Users who are viewing this thread

Back
Top Bottom