magic eight ball

arkres

Registered User.
Local time
Today, 17:28
Joined
Sep 26, 2001
Messages
62
Hey,

I'm having a little fun with my co-workers. I'm trying to set up a button on a form that will display messages in a random fashion (like the old toy, "Magic Eight Ball") I want to write several messages and have a different one appear each time the button is pushed. Is this a possibility????? Hope so......we need the diversion!!! Thanks much.

Pat
 
Sure it can be done. You'll just need to write the code.

If you are using Access 97 or Access 2000 then you can also try this:


1. Open a database in Microsoft Access.

2. Create a new macro entitled "Magic Eight Ball" and save it without adding any instructions.

3. Drag the macro up to the toolbar. The icon should change to the picture of an eight ball.

4. Ask a question and then click the 8-Ball.
;)
 
Create Table

tblMagicEightBall

Field
------
MSG Text(100) --> I just choose this set it to what works for you

Add phrases and then call the function below.

Code:
Public Function MagicEightBall() As String
    Dim rst As New ADODB.Recordset
    Dim iMsg As Long
    Dim iUpper As Long
    Dim iLower As Long
    
        rst.Open "tblMagicEightBall", CurrentProject.Connection, adOpenStatic, adLockReadOnly
        rst.MoveFirst
        iUpper = rst.RecordCount
        iLower = rst.AbsolutePosition
        
        Randomize (0)
        iMsg = Int(iUpper - iLower) * Rnd
        
        rst.Move iMsg
        
        MagicEightBall = rst.Fields(0)

End Function


PS. Mile,
I tried what you suggested and I got the Eight Ball in the Toolbar, but I did not get any response when I clicked it.
 
Whoops! You are supposed to put a space in the macro but...

as this site says, Access 2000 crashes if you press the 8-Ball. Must only work in A97.

Was fun for a whole 20 seconds when I found out about it in my last job. :rolleyes:
 
wrote the code, travis. But I'm having trouble calling the function.
 
What sort of trouble?

Are you using Access 97? If so, the code won't immediately work - you'd need to set a reference to ADO rather than DAO.
 
arkres said:
I'm having trouble calling the function.

Is the code in a module?

If so, put on the click of your button:

Code:
MsgBox MagicEightBall
 
getting error message...."invalid SQL statement"

rst.Open "tblMagicEightBall", CurrentProject.Connection, adOpenStatic, adLockReadOnly

and yes, the code is in a module. Thanks.
 
arkres said:
rst.Open "tblMagicEightBall", CurrentProject.Connection, adOpenStatic, adLockReadOnly

I don't know ADO but, in the meantime, you could try this change;

Code:
rst.Open "SELECT * FROM tblMagicEightBall;", CurrentProject.Connection, adOpenStatic, adLockReadOnly
 
Last edited:
Whoops! Made a mess of my code tags - the [/b][/quote] shouldn't be visible. :rolleyes:
 
Did the old "Magic Eight Ball" Macro in Access 97.
Works fine :)
Thanks Mile'

So this is what MS Programers get up to in the wee small hours.

Now if I can just find the hidden "Doom" game in Excel......
 
Lister said:
Now if I can just find the hidden "Doom" game in Excel......

It's hardly Doom - it's just a stupid rolling (surreal) landscape that you can fly about on. It also lists the names of the Excel team.
 

Users who are viewing this thread

Back
Top Bottom