Between Variables (1 Viewer)

Novice1

Registered User.
Local time
Today, 02:41
Joined
Mar 9, 2004
Messages
385
First two If Then's work fine (no action) but I having trouble with the third If Then. I want the wave file to play if there are 1 to 5 records. I believe the problem the AND but I don't know how to write a between statement using the variable. Any help would be appreciated.


Dim VarCount As Variant
VarCount = Forms!frmCustomersInQueue2.Recordset.RecordCount

DoCmd.Requery

If VarCount = 0 Then
Else
If VarCount > 5 Then
Else
If VarCount > 0 And VarCount < 6 Then

Call PlayWaveFile("C:\Users\Public\Documents\SignInPlus\SignInTool\doorbell.WAV")

End If
End If
End If
 

GPGeorge

George Hepworth
Local time
Today, 02:41
Joined
Nov 25, 2004
Messages
1,918
Try this instead:

Code:
Public Sub PlaytheWav( )
      Dim VarCount As Variant
  
      VarCount = Forms!frmCustomersInQueue2.Recordset.RecordCount

      DoCmd.Requery
      Select Case VarCount
          Case 1, 2, 3, 4, 5
               PlayWaveFile("C:\Users\Public\Documents\SignInPlus\SignInTool\doorbell.WAV")
      End Select

End Sub
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Today, 17:41
Joined
May 7, 2009
Messages
19,247
you can use 1 If statement:

If VarCount > 0 And VarCount < 6 Then

Call PlayWaveFile("C:\Users\Public\Documents\SignInPlus\SignInTool\doorbell.WAV")

End If
 

The_Doc_Man

Immoderate Moderator
Staff member
Local time
Today, 04:41
Joined
Feb 28, 2001
Messages
27,229
The answer to your implied question is:

Code:
IF VarCount Between 1 and 5 THEN
    Call PlayWave...
End If

You were using >0 and <6 (an Exclusive interval), but Between ...And uses the Inclusive interval, so... between 1 and 5.
 

The_Doc_Man

Immoderate Moderator
Staff member
Local time
Today, 04:41
Joined
Feb 28, 2001
Messages
27,229
Whoops, my bad - it is not a VBA operator. However, it works in SQL.

That's what I get for answering later at night when I'm getting tired.
 

Users who are viewing this thread

Top Bottom