Ms Access VB using if

i am using the if statement   If (StartOdo <= 0) Then. what i need it to check is if StartOdo <=0 or StartOdo is blank, need it to check in one if don't want to use else if etc.
Blueice13085Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Steven HarrisPresidentCommented:
...need it to check in one if don't want to use else if etc.
Can you explain a bit further?  What is it exactly that you are trying to do?
0
Blueice13085Author Commented:
code reads

        If (StartOdo <= 0) Then
            DoCmd.SetWarnings False
            erg = MsgBox("No Start miles had been set for" & " " & Me.VehicleNumber.Column(0) & "," & " " & Me.OdoAtFillDate & " Miles " & "will be the Start Miles for this Vehicle. No other Data is Needed", vbOKOnly)
            DoCmd.RunSQL (SQL2)
            DoCmd.RunCommand (acCmdDeleteRecord)
            DoCmd.Close
            DoCmd.SetWarnings True

Open in new window



but if StartOdo is blank then it goes to a different statement in my code (no listed here)
so i need it to check it here if StartOdo is blank, less then 0, or = to 0. If StartOdo is blank do above code, StartOdo is is less then 0 or = to 0 do above code.
0
Steven HarrisPresidentCommented:
Try using:

If (Startodo <= "0") OR (IsNull(Startodo)) Then
            DoCmd.SetWarnings False
            erg = MsgBox("No Start miles had been set for" & " " & Me.VehicleNumber.Column(0) & "," & " " & Me.OdoAtFillDate & " Miles " & "will be the Start Miles for this Vehicle. No other Data is Needed", vbOKOnly)
            DoCmd.RunSQL (SQL2)
            DoCmd.RunCommand (acCmdDeleteRecord)
            DoCmd.Close
            DoCmd.SetWarnings True

Open in new window

0
printnix63Commented:
Hi,

from the code you had been proposed there is one catch, if there is no dataset you will receive an error. Basically, if you want to get around the double If/Else you can try below:

        If (Not rstVehicles.EOF) Then
            rstVehicles.MoveFirst
            startOdo = rstVehicles.Fields("StartOdo")
        End If
        MsgBox "StartOdo= " & startOdo
        
        If (IsNull(startOdo) = True) Or (startOdo <= 0) Then
            DoCmd.SetWarnings False
            erg = MsgBox("No Start miles had been set for this Vehicle, this will be StartOdo", vbOKOnly)
            DoCmd.RunSQL (SQL2)
            DoCmd.RunCommand (acCmdDeleteRecord)
            DoCmd.Close
            DoCmd.SetWarnings True
        Else
            MsgBox ("Mileage run with last fuel: " & (Me.OdoAtFillup - startOdo))
            
        End If

Open in new window


This works in my environment as well. One point to mention: If there has never been a value for this vehicle inside the tblVehicles table, you will never be able to add one by this process, as the dataset in the tblFuelLog is immediately deleted by this routine.
It may be a question to think about, whether it may be better to insert a new vehicle with this base value of fuel log, which does not happen here.

The other routine provided a possibility to decide on adding a dataset to the tblVehicle if there is no data for such a vehicle, here you are not able to distinguish and do anything about it.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Access

From novice to tech pro — start learning today.