Thanks for the reply.
This wouldn't work because I cant reference the control that needs using in this variable
VAR = Forms("frm" & MYVAR).Controls("fsub" & MYVAR).Form![VALUE]
This would need MYVAR variable which would be:
MYVAR = Forms("frm" & MYVAR).Controls("fsub" & MYVAR).Form![VALUE]
The MYVAR variable needs to be equal to a control on the form "fsub"&MYVAR on "frm"&MYVAR - ie its a circular argument. Are there any other methods? All i need to do is reference the control on the form the button is clicked on but it will not let me just type the control name. I can if the code is connected to the form module and is not an outside function.
the actual code is below
Code:
Dim Specl As String, Tss As String
Tss = "TS"
Specl = [RPSpec] 'this needs to be the control [RPSpec] on the subform the button is clicked on
but it gives 'external name not defined error' when in a module as a function. It works fine
as code connected to the form.
DoCmd.OpenForm "frmMaterialSpec", acNormal, "", "[MaterialID]=[Forms]![frm" & Specl & "].
[Form]![MaterialID] And [FailureShortHand]='" & Tss & "'", acFormReadOnly