Solved

Have Access randomly pop a message box from an array of messages

Posted on 2014-10-22
2
242 Views
Last Modified: 2014-11-06
I need some help with some vba script that pops a message box lets say 20 percent of the time from an array of messages at random

I can do the 20% by doing
If rnd() * 100 > 20 Then

Open in new window


my problem is how to write that code that on 20% of occasions gives me a random expression from

expr1, expr2, expr3, expr4

thanks in advance
If rnd() * 100 > 20 Then

Open in new window

0
Comment
Question by:damixa
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 76

Expert Comment

by:GrahamSkan
ID: 40398094
I think that you need to explain further.

How are the  variables in your hypothetical call (expr1, expr2, expr3, expr4) related to your difficulty?
0
 
LVL 47

Accepted Solution

by:
Dale Fye (Access MVP) earned 500 total points
ID: 40398113
I would start with:

If rnd() * 100 < 20 Then

If you only have 4 expressions, then I would embed a case statement inside that:

SELECT Case rnd() * 100
    Case <= 25
         msgbox "expr1"
    Case <= 50
          msgbox "expr2"
    Case <= 75
          msgbox "expr3"
    Else
           msgbox "expr4"
End Select

Open in new window

If you have more than 4 expressions, I'd put them in a table with [ID] and [Expression] fields, and use a query to select the top expression.  The query would look like:

SELECT [Expression] FROM tbl_Expressions ORDER BY rnd([ID]) ASC

And you could simply get the random expression with:

DLOOKUP("Expression", "qry_RandomExpressions")
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
It’s been over a month into 2017, and there is already a sophisticated Gmail phishing email making it rounds. New techniques and tactics, have given hackers a way to authentically impersonate your contacts.How it Works The attack works by targeti…
Familiarize people with the process of utilizing SQL Server stored procedures from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Micr…
Learn how to number pages in an Access report over each group. Activate two pass printing by referencing the pages property: Add code to the Page Footers OnFormat event to capture the pages as there occur for each group. Use the pages property to …

737 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question