IIF VBA coding to open a specific form depending on field value

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi everyone,

Hope someone can help before I confuse myself more than I already have.

I have a form which displays data from a query, and one of these fields is a
calcualtion (remainingNoOfPlaces). What i'm trying to acheive is to have a
button that when a user clicks on the button it will open a form if
remainingNoOfPlaces is <=0 , otherwise, if it is not (i.e. >0) a completely
different form is displayed. I think its done with an IIF statement in the
VBA coding for the button, but i'm getting more and more confussed the harder
I try!

Would be greatful if someone can help,

Thanks,
Matty
 
Matty,
I'm assuming you're using Macros? If so, they are very limited with situations like
this.
Use an event procedure...

Find the Click event for the button in the button property dialog box, and select Event
Procedure from the dropdown arrow on the right..
While the cursor is still in the Click property field, click the button with 3 dots
(...)
You'll see...

Private Sub YourButtonName_Click()

End Sub

Place this code between the lines (use your own form names)

If RemainingNoOfPlaces <= 0 Then
DoCmd.OpenForm "Form1"
Else
DoCmd.openForm "Form2"
End If
 
IIf is a function, If is VBA code.

If Me!remainingNoOfPlaces > 0 then
strFrmName = "Form1"
else
strFrmName = "Form2"
end if
Docmd. OpenForm strFrmName, acNormal, "", "", , acNormal
 
Hi Al,

I'm not using Macro's for this, but have used the code in the VBA coding for
the button and it works terrific!

Many Thanks Al,

Matt
 
Back
Top