Can I put msgbox statement in the query?

coco

New member
Local time
Today, 17:57
Joined
Oct 4, 2004
Messages
6
Actually my doubt is: can I put messagebox(or Inputbox, or words like "Show report") statement in the IIf statement. For instance:

IIf(Table.[End Date]<=[EnterDate], [End Date], Msgbox("Please try again.")) AS field name

Thanks for your help.
coco
 
coco,

I have never tried it, but I seriously doubt that the IIf statement (or queries
in general) support the use of functions like MsgBox.

If you really needed to do that, you can make a Public Function, and it can
display the message box.

NewField: YourFunction([StartDate], [EndDate])

Code:
Public Function YourFunction (StartDate As Date, EndDate As Date) As Date
If EndDate < StartDate Then
   MsgBox("Here it is.")
   YourFunction = StartDate
Else
   YourFunction = EndDate
End If
End FUnction

Wayne
 
Thanks Wayne. The code looks like a VB code, right? But I would like write this in the query, how? Anyway, I'll try it and let you know.

coco
 
coco,

Access won't let you put "interactive" things in a query. The closest that
they come is if you put a field like "[SomeUnknownField]", it will bring up a
Message Box asking you for "[SomeUnknownField]".

In this case, we are circumventing it by going out to VBA. VBA will let you
display a Message box.

The down-side thing is that you may get MANY message boxes. But you
would have had that anyway if the query would have supported it.

Wayne
 

Users who are viewing this thread

Back
Top Bottom