Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Andrzejek on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Returning a value from an Unbound Subform

Status
Not open for further replies.

aj83766

Vendor
Jun 3, 2002
1
US
Hi,

I'm new to Access and am hoping that somebody can help me.
I have an unbound form that contains a text field and a button and an unbound subform. Select criteria is entered into the text field and when the button is pressed the on_click event sets the recordsource property of the subform which then displays the selected data. This bit is straight from the MS Access help pages and works fine.

The problem that I have is that I want to add another button to the master form that opens a form but passes the unique id from from the highlighted record in the subform using open_args. The code behind the button is :

Code:
Private Sub QueryPropertyMatchRun_Click()
On Error GoTo Err_QueryPropertyMatchRun_Click

    Dim stDocName As String
    Dim stLinkCriteria As String

    stDocName = "MatchProperty"
    DoCmd.OpenForm stDocName, , , stLinkCriteria, , , [Me!QueryPropertySubform!PropertyId.Value]

Exit_QueryPropertyMatchRun_Click:
    Exit Sub

Err_QueryPropertyMatchRun_Click:
    MsgBox Err.Description
    Resume Exit_QueryPropertyMatchRun_Click
    
End Sub

When the button is pressed the message displayed is:

Can't find the field Me!QueryPropertySubform!PropertyId.Value

It complains that the field is either misspelt (it isn't!), renamed or deleted.

I have tried lots of different ways to get this to work but to no avail. All help appreciated.
 
Try this:

Me!QueryPropertySubform.Form!PropertyId.Value

Or:

Forms!MainFormName!QueryPropertySubform.Form!PropertyId.Value


I pulled this out of some old notes of mine. Hope it works for you.

 
Hi!

You do use wrong options on DoCmd. You try to put filter option on wrong place.

stLinkCriteria ="PropertyId=" & [Me!QueryPropertySubform!PropertyId.Value]
'If type of field PropertyId is Text use delimiter ' on criteria string:
[/color blue]stLinkCriteria ="PropertyId='" & [Me!QueryPropertySubform!PropertyId.Value] & "'"
stDocName = "MatchProperty"
DoCmd.OpenForm stDocName, , , stLinkCriteria


Aivars
[pipe]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top