I have the folllowing code that repeats in each object
Dim strDocName As String
strDocName = “frmMain”
Dim Department As Control
Set Department = Forms![frmMain]![Department]
If IsOpen(strDocName) = True Then
If Department = 1 Then
do someting
ElseIf Department = 2 Then
do something
ElseIf Department = 3 Then
do something
ElseIf Department = 4 Then
do someting
ElseIf Department = 5 Then
do something
ElseIf Department = 6 Then
do something
End If
And here is an example:
Dim strDocName As String
strDocName = “frmMain”
Dim Department As Control
Set Department = Forms![frmMain]![Department]
If IsOpen(strDocName) = True Then
If Department = 1 Then
base = Ste
ElseIf Department = 2 Then
base = Va
ElseIf Department = 3 Then
base = Bl
ElseIf Department = 4 Then
base = Ha
ElseIf Department = 5 Then
base = Pl
ElseIf Department = 6 Then
base = Ta
End If
Me.RecordSource = base
I want to rationalize my coding and if possible not to repat one and the same condition many times.
I will be very grateful if i could simplify my coding with somebody’s help.
What i repeat in many forms and reports is the condition in my main form called frmMain. In this form i have
an option control called Department. This is a key condition in my database becasue many functions and objects depend
on the choice in my main form.Of course they are performed only if the main form is opened.
Is it possible that i do not describe each time these conditions and do not enumerate each time the different options,
but write them only once.
I imagine the code something like that:
base = ste (Forms![frmMain]Department]
base = Va((Forms![frmMain]Department])
It didnt work for me so i am asking for help, and but may be somebody might give me a better advice.So in short i want to refer to the
options
in my main control without enumerating them each time
Thanks in advance