Question about Code

cbearden

Registered User.
Local time
Today, 15:49
Joined
May 12, 2004
Messages
84
I don't know code very well...go easy on me.
How would I code something like this...

I have a checkbox that needs to be checked when BoxA and BoxB are not 0 or null.

I'm pretty sure how to do it if it was just Box A, but two I'm a little lost. I don't think I need two If statements.

Thanks in advance
 
Dim intBoxA As integer
Dim intBoxB As Integer

intBoxA = Nz(Me!BoxA,0)
intBoxB = Nz(Me!BoxB,0)

If intBoxA + IntBoxB = 0 Then
Me!chkCheck = False
Else
Me!chkCheck = True
End If


Two points. One, its not clear where this code would go. it would seem it should go in the On Current event of your form. Two, the state of the checkbox should not be stored in your table. Since it calculated you can use that code to calculate it at any time.
 
there is not calculation.
BoxA is a Refund Amt and BoxB is a received date.

I was thinking the code would go in the AfterUpdate for the Form.
Good spot?
 
Would the code be
If intBoxA And intBoxB = 0 Then...

?
 
cbearden said:
there is not calculation.
BoxA is a Refund Amt and BoxB is a received date.

Why would you need a checkbox anyway? :confused:
 
cbearden said:
Would the code be
If intBoxA And intBoxB = 0 Then...

?

If Nz(intBoxA,0) = 0 And Nz(intBoxB,) = 0 Then...
 
But surely if there's a date in the DateReceived box then you can tell that it has been recieved, thus making the checkbox surplus to requirements... ;)
 
If you need another visual indication that something has been received then why not use a label?
 
cbearden said:
there is not calculation.
BoxA is a Refund Amt and BoxB is a received date.

I was thinking the code would go in the AfterUpdate for the Form.
Good spot?

Yes there IS a calculation. The value of the checkbox is calculated based on the value of the other 2 controls.

The code would be as I wrote it. The Nz function will substitute a zero if the control contains a Null. I did this to avoid having to test for both 0 and Null in each control. If the control contains either a 0 or a Null then the variable will 0. I added them together so that only when both are = to 0 with the condition be True.
 
SJ McAbney said:
But surely if there's a date in the DateReceived box then you can tell that it has been recieved, thus making the checkbox surplus to requirements... ;)

but...what if the refund amt is left blank? I think it would help. plus if I make a query, I can just use the checkbox, rather than the two textboxes. seems to make things easier for me.
 
ScottGem said:
Yes there IS a calculation. The value of the checkbox is calculated based on the value of the other 2 controls.

The code would be as I wrote it. The Nz function will substitute a zero if the control contains a Null. I did this to avoid having to test for both 0 and Null in each control. If the control contains either a 0 or a Null then the variable will 0. I added them together so that only when both are = to 0 with the condition be True.

my bad...I thought you were taking it as the two textboxes were being calculated together.
 
Last edited:
In your original request you specified if BoxA AND BoxB were blank. So that's the way I wrote it. First, I would set the defauly value of RefundAmount to 0. Second, I would use the After Update event of DateReceived to check that a Refund was entered. For example:

If Not IsNull(Me![DateReceived]) AND Me![RefundAmount] = 0 Then
MsgBox "You must fill in a Refund Amount!", vbOKOnly
Me!RefundAmount.SetFocus
End If

Put the same code in the After Update event of the RefundAmount

As a general rule we do not store calculated values. Its better to perform the calc on the fly when needed.
 

Users who are viewing this thread

Back
Top Bottom