If text box = 1 then show button

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.
 
R

Rob Parker

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
 
L

Linq Adams via AccessMonster.com

If you were physically entering data into WeightSUM you could use its
AfterUpdate event to make the button visible, but I'm guessing you're doing
this thru code, which means the AfterUpdate event won't fire. This could be
overcome, but we'd need to know how you're doing this to show you the exact
details.

Basically, you'd set the button's Visible Property to No/False, then

Private Sub WeightSUM_AfterUpdate()
If Me.WeightSUM = 1 Then
CommandButtonName.Visible = True
Else
CommandButtonName.Visible = True
End If
End Sub


Run your code to populate WeightSUM

Call WeightSUM_AfterUpdate

To have your button only work WeightSUM = 1


Private Sub CommandButtonName_Click()
If Me.WeightSUM = 1 Then
'Code to open Query
Else
MsgBox "WeightSUM Must Equal One (1) In Order To Run Query!"
End If
End Sub
 
I

InventoryQueryGuy

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?
 
R

Rob Parker

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
 

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