Filter Question

N

niuginikiwi

Hi,
I have a button called btnEdit on the header section of a continuous form.
In the details section I have the details based on a query. (they are
planting details)
What I have have got happening at the moment is I click on btnEdit and it
opens another form (frmPlanting) and finds the record that is in focus on the
first form (continuous form) based on the PK (PlantingID) of the record.
Here is the code on btnEdit that does that:

Private Sub btnEdit_Click()
'View Plantings filtered to the current ID
DoCmd.OpenForm "frmPlanting"
If Me![PlantingID] > 0 Then
DoCmd.GoToControl "PlantingID"
DoCmd.FindRecord Me![PlantingID]
Else
If Not IsNull(Forms![frmPlanting]![PlantingID]) Then
DoCmd.DoMenuItem acFormBar, 3, 0, , acMenuVer70
End If
End If
End Sub

But instead of brining up everything on the next form (frmPlanting) when
finding and displaying the record in focus, I want to filter the only record
in focus on the first form and have that only displayed in the next form.
It must be easy doing that but I am stuck. How do I achieve that?
Any help would be much appreciated.
 
M

Marshall Barton

niuginikiwi said:
Hi,
I have a button called btnEdit on the header section of a continuous form.
In the details section I have the details based on a query. (they are
planting details)
What I have have got happening at the moment is I click on btnEdit and it
opens another form (frmPlanting) and finds the record that is in focus on the
first form (continuous form) based on the PK (PlantingID) of the record.
Here is the code on btnEdit that does that:

Private Sub btnEdit_Click()
'View Plantings filtered to the current ID
DoCmd.OpenForm "frmPlanting"
If Me![PlantingID] > 0 Then
DoCmd.GoToControl "PlantingID"
DoCmd.FindRecord Me![PlantingID]
Else
If Not IsNull(Forms![frmPlanting]![PlantingID]) Then
DoCmd.DoMenuItem acFormBar, 3, 0, , acMenuVer70
End If
End If
End Sub

But instead of brining up everything on the next form (frmPlanting) when
finding and displaying the record in focus, I want to filter the only record
in focus on the first form and have that only displayed in the next form.
It must be easy doing that but I am stuck.


Instead of those menu simulator commands, use the options on
the OpenForm method:

If Me![PlantingID] > 0 Then
DoCmd.OpenForm "frmPlanting", _
WhereCondition:= "PlantingID=" & Me!PlantingID
Else
If Not IsNull(Forms![frmPlanting]![PlantingID]) Then
DoCmd.DoMenuItem acFormBar, 3, 0, , acMenuVer70
End If
End If

I don't remember what that DoMenuItem does, which is not
surprising since DoMenuItem was deprecated way back when A95
came out (even if the stupid wizards still use it). Check
VBA Help to see if OpenForm has an anrgumet to do what you
want.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top