If text box = 1 then show button

  • Thread starter Thread starter InventoryQueryGuy
  • Start date Start date
I

InventoryQueryGuy

Any idea how I can arrange this event? I have a text box called 'WeightSUM'
which sums up values. When the value in 'WeightSUM' equals 1.0, I would like
a command button to appear.
Conversely, can I set the command button to not open the query unless
'WeightSUM' is equal to one?


Cheers.
 
You can do this using the AfterUpdate event(s) of the control(s) which
contain the data which is being summed. A single line of code should be
sufficient:
CmdBtnName.Visible = (Me.WeightSUM = 1)

You may also need this in the form's Current event, to ensure that the
button's visibility is set correctly when the form opens.

Note also that, if you are summing double or single sub-datatypes, the value
held internally may not be exactly 1 and the test will not work as expected.
You can get around that problem by choosing how close to 1 you will accept
as your criterion, and use an expression such as:
CmdBtnName.Visible = (Abs(Me.WeightSUM - 1) < 0.0000001)

HTH,

Rob
 
I think I would just like to have the button there and have the error message
and Ling has shown at the bottom there.

This is the VBA code I'm using:

Private Sub Talent_Mapping_Query_Click()
If ProSer_SkiCom_Thera.WeightSumValue = 1 Then

DoCmd.OpenQuery TalentMap
Exit Sub

Else
MsgBox "Weighting Must Total One (1) In Order To Run Query!"
End If
End Sub

I keep getting a '424' runtime error though. The debugger highlights the IF
statement.
Any idea why?
 
Assuming that your form is named ProSer_SkiCom_Thera, the error is probably
because you don't have a control named WeightSumValue.

You need a . to refer to the value of the control, thus:
If ProSer_SkiCom_Thera.WeightSum.Value = 1 Then

Alternatively, since the value is the default property when you refer to the
control itself, you can just use:
If ProSer_SkiCom_Thera.WeightSum = 1 Then

Or simpler, as both Linq and I suggested in our replies, use Me. as the
reference to the form itself:
If Me.WeightSum = 1 Then

HTH,

Rob
 
Back
Top