A2003: setting fields on form I open (1 Viewer)

bulrush

Registered User.
Local time
Today, 04:18
Joined
Sep 1, 2009
Messages
209
Win XP with A2003

I have a form called ProjectEdit. ProjectEdit shows a single record from a table called Project, with the key field being PRID. When I click an Edit button, I want to open another form, called ProjectDetailEdit, showing only detail records related to the record on ProjectEdit. My detail records on ProjectDetailEdit have many fields, the fields will not fit on a subform.

From ProjectEdit, when I open the ProjectDetailEdit, how do I set a text box on ProjectDetailEdit, called txtProjectID to contain the PRID from ProjectEdit?
Also, I would like the combo box (a search box) to show only records where PRID = the PRID from ProjectEdit, so I have to set the Rowsource for cbxSearch.

My question is, is this valid code, and the best way to do it?
PHP:
Private Sub cmdEditDetails_Click()
Dim s As String

' WHERE clause for form's filter.
s = "[PRID]=" & txtID
DoCmd.OpenForm "ProjectDetailEdit", acNormal, , s ' s sets form's filter.
Forms("ProjectDetailEdit").txtPRID = txtID

End Sub
 

Beetle

Duly Registered Boozer
Local time
Today, 02:18
Joined
Apr 30, 2011
Messages
1,808
You could pass the value in the OpenArgs property of the OpenForm method

Example code for the command button on the first form:
Code:
Private Sub cmdEditDetails_Click()
 
DoCmd.OpenForm "ProjectDetailEdit", acNormal, , "[PRID]=" & Me!txtID, , , Me!txtID
 
End Sub

Then in the Open event of the second form, set the Row Source of the combo box:
Code:
Private Sub ProjectDetailEdit_Open(Cancel As Integer)
 
Dim strRowSource As String
 
If Not IsNull(Me.OpenArgs) Then
    strRowSource = "Select SomeFields From SomeTable Where [PRID]=" & Me.OpenArgs & " Order By SomeField;"
Else
    strRowSource = "Select SomeFields From SomeTable Order By SomeField;"
End If
 
Me!cboYourCombo.RowSource = strRowSource
 
End Sub

My detail records on ProjectDetailEdit have many fields, the fields will not fit on a subform.

How many fields are we talking here? If it's more than maybe 25 or so there's a good chance your table is not properly normalized.
 

Users who are viewing this thread

Top Bottom