The same message appear-I want different each time i open a form

A

ake

I have created a query that will randomly select a "quote" from a table. I
also made it appear in a startup form.My problem is that whenever I open the
form the same message appears. I want a different message whenever I open the
form. Please help me do this. I know I'm missing just one thing here and I
can't figure it out.
I entered the following SQL in my table:

SELECT TOP 1 [tblQuotes].[Message], Rnd([Auto]) AS Expr1
FROM tblQuotes
ORDER BY Rnd([Auto]);

Thanks!
 
J

John W. Vinson

I have created a query that will randomly select a "quote" from a table. I
also made it appear in a startup form.My problem is that whenever I open the
form the same message appears. I want a different message whenever I open the
form. Please help me do this. I know I'm missing just one thing here and I
can't figure it out.
I entered the following SQL in my table:

SELECT TOP 1 [tblQuotes].[Message], Rnd([Auto]) AS Expr1
FROM tblQuotes
ORDER BY Rnd([Auto]);

Put this little function into a Module:

Public Function RndNum(vIgnore As Variant) As Double
Static bRnd As Boolean
If Not bRnd Then
'Initialize the random number generator once only
bRnd = True
Randomize
End If
RndNum = Rnd()
End Function

Then use RndNum([Auto]) as the argument in the query rather than Rnd(). This
will reinitialize the random number generator each time.
 
A

ake

Thanks a lot,this works..Happy Holidays!

John W. Vinson said:
I have created a query that will randomly select a "quote" from a table. I
also made it appear in a startup form.My problem is that whenever I open the
form the same message appears. I want a different message whenever I open the
form. Please help me do this. I know I'm missing just one thing here and I
can't figure it out.
I entered the following SQL in my table:

SELECT TOP 1 [tblQuotes].[Message], Rnd([Auto]) AS Expr1
FROM tblQuotes
ORDER BY Rnd([Auto]);

Put this little function into a Module:

Public Function RndNum(vIgnore As Variant) As Double
Static bRnd As Boolean
If Not bRnd Then
'Initialize the random number generator once only
bRnd = True
Randomize
End If
RndNum = Rnd()
End Function

Then use RndNum([Auto]) as the argument in the query rather than Rnd(). This
will reinitialize the random number generator each time.
 

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