UtterAccess.com
X   Site Message
(Message will auto close in 2 seconds)

Welcome to UtterAccess! Please ( Login   or   Register )

Custom Search
 
   Reply to this topicStart new topic
> Improving An If Statement In Vba, Access 2016    
 
   
hedge
post Sep 19 2019, 04:17 PM
Post#1



Posts: 506
Joined: 17-November 08



Hi,

I have the below IF statement as part of a VBA code. It basically checks something and if true runs the macro, then if not moves to the next step etc.

Is there a way to make it work so that if the statement is true on step 1, it not only runs the macro but then also checks to see if step 2 is true or false and then goes to the last check as well.

I am thinking a loop or something, but just not to familiar with loops to do it. or maybe there is an easier way.

CODE
If DCount("*", "Query_1") > 0 Then

DoCmd.RunMacro "Macro_1"

Else

If [Forms]![Inv_button]![txtUserID] = "ABCD" Then

DoCmd.RunMacro "Macro_ABCD"


Else

DoCmd.RunMacro "Macro_remaining_items"

End If






Thanks,
Go to the top of the page
 
tina t
post Sep 19 2019, 04:36 PM
Post#2



Posts: 6,107
Joined: 11-November 10
From: SoCal, USA


no loop. you just need a nested If statement, as

CODE
If DCount("*", "Query_1") > 0 Then
    DoCmd.RunMacro "Macro_1"
    If [Forms]![Inv_button]![txtUserID] = "ABCD" Then
        DoCmd.RunMacro "Macro_ABCD"
    Else
        DoCmd.RunMacro "Macro_remaining_items"
    End If
End If

see if the above does what you want. if not, maybe restate exactly what you want to happen, to help me understand it better.

hth
tina
This post has been edited by tina t: Sep 19 2019, 04:37 PM

--------------------
"the wheel never stops turning"
Go to the top of the page
 
hedge
post Sep 19 2019, 04:44 PM
Post#3



Posts: 506
Joined: 17-November 08



I will give that a shot, basically just remove the "else" in the middle which makes total sense.

Thanks,
Go to the top of the page
 


Custom Search


RSSSearch   Top   Lo-Fi    15th October 2019 - 11:11 AM