
Originally Posted by
j9070749
I have a form, which is also used as a subform. The code needs to be changed depending on which form it is opened in. I have tried some code which is shown below, but bring up the error 'can't find the form stdocname'. Can anyone help please?
Thanks
Dim stDocName as string
if formname ="[Records]" then stDocName = "[Records]"
else
stDocName = "[Demogrpahics]"
ID = [Forms]![stDocName]![Patient ID Number]
There are a few problems:
1) "formname" has not been declared (ie DIM formname as ????) Or is "formname" a control on a form?? If so, then it is better to use "Me.formname" (without the quotes)
2) "stDocName" is a variable, so of course [Forms]![stDocName]![Patient ID Number] will cause an error. ("stDocName" is not the name of a form)
3) The syntax for the IF() function is wrong. There are two forms of the IF() function. One is the single line form; "ELSE" is not allowed (try to avoid this form). The other form requires "END IF" to terminate the function.
Without knowing the rest of the code, you could try:
Code:
Dim stDocName as string
IF Me.formname ="[Records]" then
stDocName = "[Records]"
ID = [Forms]![Records]![Patient ID Number] ' what is ID??? a control or a variable??
ELSE
stDocName = "[Demogrpahics]"
END IF