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

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
 
A

Al Camp

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
 
J

jahoobob via AccessMonster.com

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
 
G

Guest

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top