How do I open different forms dependant on a field value?

H

huzzlepuzzle

Hi there,

I'm a bit stuck - I need to be able to open different forms dependant upon
the field "Region" in a datasheet subform when selecting and doubleclicking
on a particlar line in there.

eg. if this record on mysubform value region = US then Openform
"AddinUSFormat", or if region = AP then Openform "AddinAPformat" or if Region
.......

I think that this is possible using a nested If and setting document names
but I'm really struggling with the coding,

Can somebody advise?

Thanks for the help
 
G

Gijs Beukenoot

From huzzlepuzzle :
Hi there,

I'm a bit stuck - I need to be able to open different forms dependant upon
the field "Region" in a datasheet subform when selecting and doubleclicking
on a particlar line in there.

eg. if this record on mysubform value region = US then Openform
"AddinUSFormat", or if region = AP then Openform "AddinAPformat" or if Region
......

I think that this is possible using a nested If and setting document names
but I'm really struggling with the coding,

Can somebody advise?

Thanks for the help

One:
Dim strFormName as string

If Me.<FieldIdentifyingRegion> = "US" then
strFormName = "AddinUSFormat"
else
strFormName = "AddinAPFormat"
endif
docmd.openform(strFormName)

Or two:
If Me.<FieldIdentifyingRegion> = "US" then
docmd.openform("AddinUSFormat")
else
docmd.openform("AddinAPFormat")
endif

Both can be extended with ElseIf's or, modified to a Select Case when
more regions need to be checked.
The second one is 'harder' to maintain if, for example, you want to
have them to open in dialog mode: you'll need to modify every
docmd.openform where in the first sample theere's only 1
docmd.openform.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top