Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Action from a command button

Status
Not open for further replies.

dommales

MIS
Aug 10, 2001
10
GB
Ok, now this is a good one, Probably very basic, but it needs to be done.

Can I add a Iif statement to a command button to open the specific query, dependant on a value in a database field?

For example:

IIf([Contractor Details]![Contract Type]="AGENCY",/OPEN AGENCY QUERY/,IIf([Contractor Details]![Contract Type]="PAYE",/OPEN PAYE QUERY/,IIf([Contractor Details]![Contract Type]="LTD - DIRECT",/OPEN LTD QUERY/,/DO NOTHING/)))

Any advice?

I have spent the past 3 hours looking for an answer and have been unsuccesful.

Ta

Dom.
 
Hi Dom!

What you probably want is a Select Case statement like this:

Select Case [Contractor Details]![Contract Type]

Case "Agency"
DoCmd.RunSQL "AgencyQuery"
Case "Paye"
DoCmd.RunSQL "PayeQuery"
etc.

End Select

hth
Jeff Bridgham
 
You probably should do this as a case statement in VBA code. In the on_click event of the button create an event procedure. Is [Contract Type] a field on your form?


Select Case me![Contract Type]
Case "Agency"
docmd.openquery "query1"
Case "Paye"
docmd.openquery "query2"
Case "Ltd"
docmd.openquery "query3"
etc
End select Maq B-)
<insert witty signature here>
 
LOL, Jeff. We're doing it again. Maq B-)
<insert witty signature here>
 
Hi Maq!

I dare say you are some kind of genius!! :)

Jeff
 
Here is how the if statement would look like in a command button.

Private Sub CmdButton_Click ()

If Contract_Type = &quot;Agency&quot; Then
'Do Something Here
Else
'Do Something Else Here
End if

The above is based on the assumption that the field is located on your form. If this is not what you want, please provide more detail as to what you are trying to acomplish.
ljprodev@yahoo.com
ProDev, MS Access Applications B-)
 
Thanks for the help all, but in the time of posting and the time I picked up a reply, I have used conditions in a macro to achieve the same results.

Thanks so much and I am sorry for wasting all you time.

Dom
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top