Acc97 - If, Then, Else ?????????

  • Thread starter Thread starter noodnutt
  • Start date Start date
N

noodnutt

G'day ppl

I never seem to be able to get the ol' "if, then" into proper context, now I
know I can simplify this by having the user type in the data, but for
reasons of aestetics & convenience I am trying this, so here's the problem:

Private Sub Btn1_Click()

If Me.Drawn1 = 0 Then
Me.Drawn1 = 1
Else
If Me.Drawn1 > 0 Then
Me.Drawn2 = 1
Else
If Me.Drawn2 > 0 Then
Me.Drawn3 = 1
Else
If Me.Drawn3 > 0 Then
Me.Drawn4 = 1
Else
If Me.Drawn4 > 0 Then
Me.Drawn5 = 1
Else
If Me.Drawn5 > 0 Then
Me.Drawn6 = 1
Else
If Me.Drawn6 > 0 Then
Me.Sup1 = 1
Else
If Me.Sup1 > 0 Then
Me.Sup2 = 1
End If
End If
End If
End If
End If
End If
End If
End If

End Sub

What this should do is that if Drawn1 has no value then it will = 1, else if
it already has a value then goto the next and so on.

I tried using an option group, but that didn't work either, and I'm not
quite sure a CaseSelect is relavent here or not, so here I am "AGAIN",
relying on those I know who will set me straight, looking forward to your
taunts & jibes, oh, and possibly your suggestions.

TIA

Reg's

Mark
 
Hi,


Zero *is* a value: it is the origin, where you start to measure:
being at 5 meter from a tower, 5 is a localization, 5 is a value; being at 0
meter from the same tower is ALSO a localization, 0 is a localization, 0 is
a value. To test if a "value type" has a "value" or not, try:


If IsNull(Me.ControlName) Then
...
End If




Hoping it may help
Vanderghast, Access MVP
 
noodnutt said:
G'day ppl

I never seem to be able to get the ol' "if, then" into proper context, now I
know I can simplify this by having the user type in the data, but for
reasons of aestetics & convenience I am trying this, so here's the problem:

Private Sub Btn1_Click()

If Me.Drawn1 = 0 Then
Me.Drawn1 = 1
Else
If Me.Drawn1 > 0 Then
Me.Drawn2 = 1
Else
If Me.Drawn2 > 0 Then
Me.Drawn3 = 1
Else
If Me.Drawn3 > 0 Then
Me.Drawn4 = 1
Else
If Me.Drawn4 > 0 Then
Me.Drawn5 = 1
Else
If Me.Drawn5 > 0 Then
Me.Drawn6 = 1
Else
If Me.Drawn6 > 0 Then
Me.Sup1 = 1
Else
If Me.Sup1 > 0 Then
Me.Sup2 = 1
End If
End If
End If
End If
End If
End If
End If
End If

End Sub

What this should do is that if Drawn1 has no value then it will = 1, else if
it already has a value then goto the next and so on.

I tried using an option group, but that didn't work either, and I'm not
quite sure a CaseSelect is relavent here or not, so here I am "AGAIN",
relying on those I know who will set me straight, looking forward to your
taunts & jibes, oh, and possibly your suggestions.

TIA

Reg's

Mark
Mark,

I'm not sure what you are trying to do. If Drawn1>0, do you want to set
Drawn2-6 and Sup1 & Sup2 to 1? More examples of what you want, please.


The way you have it written, after a condition evaluates to true, none
of the following conditions will be evaluated.

So if Drawn3>0, only Drawn4 is set to 1. None of the other variables are
changed.


Can Drawn1 ever be less than zero? The only time the conditions for
Drawn2-6 and Sup1-2 get evaluated is if Drawn1 is less than zero.
 
noodnutt said:
G'day ppl

I never seem to be able to get the ol' "if, then" into proper context, now I
know I can simplify this by having the user type in the data, but for
reasons of aestetics & convenience I am trying this, so here's the problem:

Private Sub Btn1_Click()

If Me.Drawn1 = 0 Then
Me.Drawn1 = 1
Else
If Me.Drawn1 > 0 Then
Me.Drawn2 = 1
Else
If Me.Drawn2 > 0 Then
Me.Drawn3 = 1
Else
If Me.Drawn3 > 0 Then
Me.Drawn4 = 1
Else
If Me.Drawn4 > 0 Then
Me.Drawn5 = 1
Else
If Me.Drawn5 > 0 Then
Me.Drawn6 = 1
Else
If Me.Drawn6 > 0 Then
Me.Sup1 = 1
Else
If Me.Sup1 > 0 Then
Me.Sup2 = 1
End If
End If
End If
End If
End If
End If
End If
End If

End Sub

What this should do is that if Drawn1 has no value then it will = 1, else if
it already has a value then goto the next and so on.

I tried using an option group, but that didn't work either, and I'm not
quite sure a CaseSelect is relavent here or not, so here I am "AGAIN",
relying on those I know who will set me straight, looking forward to your
taunts & jibes, oh, and possibly your suggestions.

TIA

Reg's

Mark
Not to confuse the situation. I personally find it easer to use "Select
Case" to provide multiple conditions.
 
Hi,


A Select Case would "fire" only once. Here multiple conditions could
hold at the same time (Drawn1>0 and Drawn2 >0) and would command an action
for each cases the condition is found true.


Vanderghast, Access MVP
 
My apologies guy's

If txtDrawn1 IsNull then thats where the value is inserted, but if it
IsNotNull then the value is to be placed in txtDrawn2 etc.

The person who will be using this is way down the food chain of tech
knowledge due to her age, so to simplify it I have inserted 45 large buttons
labelled 1 through to 45 so she can read them. All she has to do is click on
the numbers that were drawn.

HTH

Mark.
 
More clarifications

Yes Steve, the value will be anything from 1 - 45 although when a new record
is opened it will be 0 or Null.

Lets assume the lotto No's for this week were:
26 - 3 - 13 - 24 - 39 - 45 | 20 = 22|

The elderly user will click on the coreesponding buttons that I have setup.

So, Drawn1=26, Drawn2=3 etc, so if Drawn1 already has a value, the code will
place the next value into Drawn2 etc.

HTH.

Mark
 
I sat up all night wondering where the sun went when it went down and
then it dawned on me.....

A lotto checker!! I've been doing it is Excel. It's quick but a lot of
typing to get the numbers entered. This has given me ideas.

Anyway, enough about me. This is how I attacked your problem; there are
probably better ways, but...


In the table, Drawn1 - Drawn6 and Sup1 & Sup2, the 'Default Value'
should be zero.

Now the code:

'---begin code-----
I named the buttons btn1, btn2, btn3, ..., btn45. Then I created a Click
event for each button:

Private Sub btn1_Click()
HandleDraw (1)
End Sub

Private Sub btn2_Click()
HandleDraw (2)
End Sub

Private Sub btn3_Click()
HandleDraw (3)
End Sub

'
' the rest of the buttons go here
'
'

Private Sub btn45_Click()
HandleDraw (45)
End Sub

'HandleDraw() is a subroutine that puts the value of the button clicked
'into the next control that is equal to zero:

Private Sub HandleDraw(thisDraw As Integer)

If Nz(Me.intDrawn1, 0) = 0 Then
Me.intDrawn1 = thisDraw
ElseIf Nz(Me.intDrawn2, 0) = 0 Then
Me.intDrawn2 = thisDraw
ElseIf Nz(Me.intDrawn3, 0) = 0 Then
Me.intDrawn3 = thisDraw
ElseIf Nz(Me.intDrawn4, 0) = 0 Then
Me.intDrawn4 = thisDraw
ElseIf Nz(Me.intDrawn5, 0) = 0 Then
Me.intDrawn5 = thisDraw
ElseIf Nz(Me.intDrawn6, 0) = 0 Then
Me.intDrawn6 = thisDraw
ElseIf Nz(Me.intSup1, 0) = 0 Then
Me.intSup1 = thisDraw
ElseIf Nz(Me.intSup2, 0) = 0 Then
Me.intSup2 = thisDraw
End If

End Sub
'---end code-----

The NZ(Me.intDrawn1, 0) takes care of Nulls if there happens to be one.
Don't use a space to delete a number. You *HAVE* to use a zero!

Note that I used intDrawn1 as the control name on the form that has a
control source of Drawn1 (the name of the field in the table).


I used the IF...THEN...ELSEIF syntax because it is easier to type and
to follow the logic.


HTH
 
Your a genius Steve,

It works a treat, better than I had expected.

Thx heaps.

By the way, I have a lotto average draw worksheet, if you are interested, I
will e-mail it to you, it is only a small workbook.

You can e-mail me direct if you like.

Thx heaps again Steve.

Reg's
Mark.
 
noodnutt said:
Your a genius Steve,

It works a treat, better than I had expected.

Thx heaps.

By the way, I have a lotto average draw worksheet, if you are interested, I
will e-mail it to you, it is only a small workbook.

You can e-mail me direct if you like.

Thx heaps again Steve.

Reg's
Mark.

Nope, not even close. It was something I remembered seeing here a long
while ago.

Genius... isn't that just below MVP??? <grin>
 
Back
Top