can a query result in Form or Macro?

orchbelt00

New member
Local time
Today, 11:49
Joined
Jul 21, 2009
Messages
7
is it possible to write a select query in MS Access which reads

=iif([optionA]=[optionB],[open FormAlpha],[run MacroBeta])

:confused:
 
is it possible to write a select query in MS Access which reads

=iif([optionA]=[optionB],[open FormAlpha],[run MacroBeta])

:confused:

I am not aware of how to do it that way DIRECTLY, but what you want can be achieved via either a Macro or a VB Code Procedure/Function. I prefer the VB Code approach because of the superior Error Handling Capabilities.
 
I am not aware of how to do it that way DIRECTLY, but what you want can be achieved via either a Macro or a VB Code Procedure/Function. I prefer the VB Code approach because of the superior Error Handling Capabilities.


Can you please provide me with the code needed to accomplish the task?
Thanks
 
Can you please provide me with the code needed to accomplish the task?
Thanks

That will be difficult without additional information regarding the inputs, but something like:
Code:
Private Sub YourSub
    On Error GoTo Error_YourSub
.
.   Additional Code needed goes here
.
    If Me.optionA = Me.optionB Then
        DoCmd.OpenForm "FormAlpha", acNormal, "", "", , acWindowNormal
    Else
        DoCmd.RunMacro "", {RepeatCount}, {RepeatExpression}
    EndIf
.
.   Additional Code needed goes here
.
Exit_YourSub:
    Exit Function
 
Error_YourSub:
 
    MsgBox "An Error Has Occurred"
    Resume Exit_YourSub
 
End Sub
 
That will be difficult without additional information regarding the inputs, but something like:
Code:
Private Sub YourSub
    On Error GoTo Error_YourSub
.
.   Additional Code needed goes here
.
    If Me.optionA = Me.optionB Then
        DoCmd.OpenForm "FormAlpha", acNormal, "", "", , acWindowNormal
    Else
        DoCmd.RunMacro "", {RepeatCount}, {RepeatExpression}
    EndIf
.
.   Additional Code needed goes here
.
Exit_YourSub:
    Exit Function
 
Error_YourSub:
 
    MsgBox "An Error Has Occurred"
    Resume Exit_YourSub
 
End Sub


Thanks for the info. Let me provide some additional information, hoping another response might clear up my confusion...sorry!


I am trying to simulate a log on screen. I have an "ID" field and a "Password" field on the mainscreen. These two fields are linked to an update only (no add or delete) table (Login) which updates when the end user clicks a the "Log In" button. I also have a static table (LoginDatabank) with two columns. Column 1 contains a list of all log in IDs and Column 2 is a list of all the respective passwords (the passwords are masked with "*"s). Clicking on the "Log In" button on the home screen prompts a query with the following code:

Expr1: IIf([Login.ID]=[LoginDatabank.ID],IIf([Login.PASSWORD]=[LoginDatabank.PASSWORD],{open form "homepage"},{run macro "exit"},{run macro "exit"}))

I'm assuming that using VBA as an "upon click" event would allow me to delete the above select query...

FYI - I know it's as simple as holding the left shift to bypass all of this, but the people I'm writing this for doesn't :D

Thanks for your help!!
 

Users who are viewing this thread

Back
Top Bottom