1. ## Between Values (A2k)

The following snippet of code looks for two things, I can't quite get it to perform correctly.

<pre>If Me.Paint > 0.25 And Me.Paint < 3 Then
intPaint = MsgBox("Is This A Paint Operation or A Blend Operation" & vbCrLf & _
"For Blend Press OK:" & vbCrLf & _
"For Paint Only Press Cancel:", vbOKCancel, "Blend Paintwork")
ElseIf Me.Paint <= 0.24 Then</pre>

It should be:
If less than 0.25 then do something.
If equal to 0.25 and between 0.25 and 3 then do something else.

The <3 is causing the problem because 0.25 or 0.24 is less than 3 ???

How should I change the above ?

2. ## Re: Between Values (A2k)

If Me.Paint is greater than than .25 and less than .3, then do something,
Or if Me.Paint is Less than or equal to .24, then do something else.

Your code gets skipped entirely if Me.paint is = .25 or if it is >=.3! Of course, this all assume that you can't have values such as .245; which will also be skipped.

Exactly what is it you are trying to do?

3. ## Re: Between Values (A2k)

The equation seems to work, ie the intPaint msgbox fires but doesn't apply the " - Blend" to the end of the text value.

<pre>Private Sub Paint_AfterUpdate()
Dim intPaint As Integer
Select Case id
Case "New"
'MsgBox "N"
Case "Rep"
'MsgBox "R"
Case Else
Me.id = "Pai"
If Me.Paint >= 0.25 And Me.Paint <= 3 Then
intPaint = MsgBox("Is This A Paint Operation or A Blend Operation" & _
vbCrLf & "For Blend Press OK:" & vbCrLf & _
"For Paint Only Press Cancel:", vbOKCancel, "Blend Paintwork")
ElseIf Me.Paint < 0.25 Then
Me.Paint = 0
Select Case intPaint
Case vbOK
Me.Item = Me.Item & " - " & "Blend"
DoCmd.RunCommand acCmdSaveRecord
Me.Refresh
Case vbCancel
MsgBox "Paint Only Selected"
End Select
End If
End Select
End Sub</pre>

4. ## Re: Between Values (A2k)

Dave,

Here is your code again, but with proper indentation:

Private Sub Paint_AfterUpdate()
Dim intPaint As Integer
Select Case ID
Case "New"
'MsgBox "N"
Case "Rep"
'MsgBox "R"
Case Else
Me.ID = "Pai"
If Me.Paint >= 0.25 And Me.Paint <= 3 Then
intPaint = MsgBox("Is This A Paint Operation or A Blend Operation" & _
vbCrLf & "For Blend Press OK:" & vbCrLf & _
"For Paint Only Press Cancel:", vbOKCancel, "Blend Paintwork")
ElseIf Me.Paint < 0.25 Then
Me.Paint = 0
Select Case intPaint
Case vbOK
Me.Item = Me.Item & " - " & "Blend"
DoCmd.RunCommand acCmdSaveRecord
Me.Refresh
Case vbCancel
MsgBox "Paint Only Selected"
End Select
End If
End Select
End Sub

If you look carefully, you will see that intPaint = MsgBox(...) is in the If Me.Paint >= 0.25 And Me.Paint <= 3 Then part, but Select Case intPaint is in the ElseIf Me.Paint < 0.25 Then part, so if the message box is shown, the Select Case is not executed and vice versa. The Select Case ... End Select block must be moved up, to immediately below the intPaint = MsgBox(...) instruction, or moved out of the If ... ElseIf ... End If block entirely.

This kind of problem is almost impossible to solve if the code hasn't been indented consistently. Indentation is not just a way to make code look pretty, it also helps to understand its structure.

5. ## Re: Between Values (A2k)

( Sung ) "I can see clearly now the intPaint has gone" <img src=/S/sing.gif border=0 alt=sing width=24 height=20>

<pre>Private Sub Paint_AfterUpdate()
Dim intPaint As Integer
Select Case id
Case "New"
'MsgBox "N"
Case "Rep"
'MsgBox "R"
Case Else
Me.id = "Pai"
If Me.Paint >= 0.25 And Me.Paint <= 3 Then
intPaint = MsgBox("Is This A Paint Operation or A Blend Operation" & _
vbCrLf & "For Blend Press OK:" & vbCrLf & _
"For Paint Only Press Cancel:", vbOKCancel, "Blend Paintwork")
Select Case intPaint
Case vbOK
Me.Item = Me.Item & " - " & "Blend"
DoCmd.RunCommand acCmdSaveRecord
Me.Refresh
Case vbCancel
MsgBox "Paint Only Selected"
End Select
ElseIf Me.Paint < 0.25 Then
Me.Paint = 0
End If
End Select
End Sub</pre>

6. ## Re: Between Values (A2k)

Is this what you're trying to do? This will give you between 0.25 and 3 ...

If Me.Paint >= 0.25 And Me.Paint <= 3 Then
intPaint = MsgBox("Is This A Paint Operation or A Blend Operation" & vbCrLf & _
"For Blend Press OK:" & vbCrLf & _
"For Paint Only Press Cancel:", vbOKCancel, "Blend Paintwork")
ElseIf Me.Paint < 0.25 Then

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•