Setting values

  • Thread starter Thread starter Dmac
  • Start date Start date
D

Dmac

Here is what I have. I have a form with a couple of command buttons called
cmdAB and cmdCD respectively. When you click the cmdAB command button it
opens the frmABSwitchboard, and the cmdCD opens the frmCDSwitchboard.

Both switchboards has 4 unbound text boxes with the visible property set to
no. Each text box is given a value when the form opens depending on the
value from the txtUnit text box from the frmUnitInfo form.

Dim iUnit As Integer

''' value from text box on frmUnitInfo- hidden mode
iUnit = Forms!frmUnitInfo!txtUnit

If iUnit = 1 Then
Me.BFrom.Value = "100" ' Range of cells on B Wing
Me.BTo.Value = "131"
Me.AFrom.Value = "200" ' Range of cells on A Wing
Me.ATo.Value = "231"
ElseIf iUnit = 2 Then
Me.BFrom.Value = "100"
Me.BTo.Value = "125"
Me.AFrom.Value = "200"
Me.ATo.Value = "225"
End If

frmCDSwitchboard is the same as AB except the range of cells are different.

What I would like to do is cut out the two different switchboards. Have
only one switchboard an fill the unbound text boxes with the values of the
respective wings depending on which command button was clicked.

I am doubling my work on everything I am creating. If I create a report for
one switchboard, I have to create a second report for the other switchboard
because the reports reference the values from the text boxes.

I sure would appreciate any assistance. Treat me with kid gloves, I am a
self taught newbie :-).

Thanks in advance.
 
Hello Dmac.

Dmac said:
Here is what I have. I have a form with a couple of command
buttons called cmdAB and cmdCD respectively. When you click
the cmdAB command button it opens the frmABSwitchboard, and
the cmdCD opens the frmCDSwitchboard.

Both switchboards has 4 unbound text boxes with the visible
property set to no. Each text box is given a value when the
form opens depending on the value from the txtUnit text box
from the frmUnitInfo form.

Dim iUnit As Integer

''' value from text box on frmUnitInfo- hidden mode
iUnit = Forms!frmUnitInfo!txtUnit

If iUnit = 1 Then
Me.BFrom.Value = "100" ' Range of cells on B Wing
Me.BTo.Value = "131"
Me.AFrom.Value = "200" ' Range of cells on A Wing
Me.ATo.Value = "231"
ElseIf iUnit = 2 Then
Me.BFrom.Value = "100"
Me.BTo.Value = "125"
Me.AFrom.Value = "200"
Me.ATo.Value = "225"
End If

frmCDSwitchboard is the same as AB except the range of cells are
different.

What I would like to do is cut out the two different switchboards.
Have only one switchboard an fill the unbound text boxes with the
values of the respective wings depending on which command button
was clicked.

I am doubling my work on everything I am creating. If I create a
report for one switchboard, I have to create a second report for
the other switchboard because the reports reference the values from
the text boxes.

I sure would appreciate any assistance. Treat me with kid gloves,
I am a self taught newbie :-).

All right.
The DoCmd.OpenForm method has an optional argument called OpenArgs.
You can use this argument in the event procedures of cmdAB and cmdCD
to tell the (then only one) switchboard the name of the button that
opened the switchboard form:

Private Sub cmdAD_Click()
DoCMd.OpenForm FormName:="frmABCDSwitchboard", OpenArgs:="cmdAB"
End Sub

Private Sub cmdCD_Click()
DoCMd.OpenForm FormName:="frmABCDSwitchboard", OpenArgs:="cmdCD"
End Sub

The code in the open event of the switchboard then would look like:

Dim iUnit As Integer

''' value from text box on frmUnitInfo- hidden mode
iUnit = Forms!frmUnitInfo!txtUnit
If Me.OpenArgs = "cmdAB" Then
If iUnit = 1 Then
Me.BDFrom.Value = "100" ' Range of cells on B Wing
Me.BDTo.Value = "131"
Me.ACFrom.Value = "200" ' Range of cells on A Wing
Me.ACTo.Value = "231"
ElseIf iUnit = 2 Then
Me.BDFrom.Value = "100"
Me.BDTo.Value = "125"
Me.ACFrom.Value = "200"
Me.ACTo.Value = "225"
End If
ElseIf Me.OpenArgs = "cmdCD" Then
If iUnit = 1 Then
Me.BDFrom.Value = "99" ' Range of cells on C Wing
Me.BDTo.Value = "133"
Me.ACFrom.Value = "199" ' Range of cells on D Wing
Me.ACTo.Value = "232"
ElseIf iUnit = 2 Then
Me.BDFrom.Value = "99"
Me.BDTo.Value = "126"
Me.ACFrom.Value = "199"
Me.ACTo.Value = "226"
End If
End If

I have just invented some values for the CD part.
You will probably have to adjust the half of your reports that you
decide to keep such that they reference the correct textbox names.
 
Thank you very much for your response. I have always read about the
OpenArgs but I never really understood how it all worked. And it works
beautifully. I am sure I am not any different from the rest. The more I
learn the more I realize that I could have probably done this differently
and been a lot more efficent. Every project I get involved in the more I
learn and the more I want to learn, not to mention the more I learn the more
doors get opened and I (start) to think outside the box.

Thanks again.
 

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

Back
Top