OpenForm - Where condition

C

chris

On a main form giving "Organisation" details I have a subform showing
brief details of persons associated with that organisation in
continuous forms format. By clicking on the record selector of a
record in this sub form I want to open a form which gives complete
information about the relationship between the organisation and the
person. I am using the following code to do this

Private Sub Form_DblClick(Cancel As Integer)
DoCmd.OpenForm "frmEditPerOrg", , , "PerOrgID = " & Me!PerOrgID
End Sub

However frmEditPerOrg opens with a blank new record, not the one
specified in the where condition. I have checked the filter property
of the form and it contains the correct PerOrgID but it hasn't been
applied.

I have already used exactly the same procedures elsewhere in the
database for relatioships between "Projects" and "people" and
"Projects" and "organisations" and these work as I would want. In
other cases such as the one above this just opens a new record. I
can't see what is making the difference.

Can anyone suggest the source of the problem or how I might
investigate it further. I've run out of ideas!
Chris
 
R

Rick Brandt

chris said:
On a main form giving "Organisation" details I have a subform showing
brief details of persons associated with that organisation in
continuous forms format. By clicking on the record selector of a
record in this sub form I want to open a form which gives complete
information about the relationship between the organisation and the
person. I am using the following code to do this

Private Sub Form_DblClick(Cancel As Integer)
DoCmd.OpenForm "frmEditPerOrg", , , "PerOrgID = " & Me!PerOrgID
End Sub

However frmEditPerOrg opens with a blank new record, not the one
specified in the where condition. I have checked the filter property
of the form and it contains the correct PerOrgID but it hasn't been
applied.

I have already used exactly the same procedures elsewhere in the
database for relatioships between "Projects" and "people" and
"Projects" and "organisations" and these work as I would want. In
other cases such as the one above this just opens a new record. I
can't see what is making the difference.

Can anyone suggest the source of the problem or how I might
investigate it further. I've run out of ideas!
Chris

Does the form you are opening have any code in its Open or Load event?
 
L

Linq Adams via AccessMonster.com

Your code is, I believe, set up assuming that PerOrgID is numeric data type.
Is it, perhaps, text instead?
 
C

chris

Thank you both for your suggestions. I have rechecked the points you
raised and no, there isn't any code attached to the load or open
events. There is very little code behind the form I am opening. It is
as follows:

Option Compare Database

Private Sub cmdClose_Click()
On Error GoTo Err_cmdClose_Click
'Debug.Print OpenArgs

DoCmd.Close
DoCmd.Requery
Exit_cmdClose_Click:
Exit Sub

Err_cmdClose_Click:
MsgBox Err.Description
Resume Exit_cmdClose_Click

End Sub

Private Sub OrgName_Enter()
If Trim(Nz(Me.OrgName, vbNullString)) = vbNullString Then
DoCmd.OpenForm "frmFindOrganisation", , , , , , "frmEditPerOrg"
End If
End Sub

Private Sub cmdDelete_Click()
On Error GoTo Err_cmdDelete_Click

The


DoCmd.DoMenuItem acFormBar, acEditMenu, 8, , acMenuVer70
DoCmd.DoMenuItem acFormBar, acEditMenu, 6, , acMenuVer70
DoCmd.Close
'Requery to refresh subform and remove deleted record
DoCmd.Requery


Exit_cmdDelete_Click:
Exit Sub

Err_cmdDelete_Click:
MsgBox Err.Description
Resume Exit_cmdDelete_Click

End Sub

The PerOrgID field is numeric. In fact both of the forms involved in
this problem are based on the same query. This query (qryPerOrg) is
based on a table (tblPerOrg) holding details of the relationship
between a project and people along with tblOrganisation and tblPerson
which hold full details of people and organisations. PerOrgID is an
autonumber field and is the primary key of tblPerOrg.

Any more thoughts?
Chris
 
Top