Hi,
Can anybody advise on how i can get a random tip/joke of the day to display on a specific form within my d/base? I'd like to to scroll around for as long as the form is open and display a new tip/joke everyday.
Thanks
Create a Table named tblTips. This Table will contain only 2 Fields, Field Number 1 will be TipID [INTEGER]. Make TipID the Primary Key but do not make it an AutoNumber. The entries in this Field should start at 1 and should be sequential in nature as in: 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, etc.). Field Number 2 will be Tip (STRING) and will contain the actual Tip itself. Place this code wherever appropriate, to generate a Random Tip. The code is self-maintaining as long as you keep the TipIDs sequential. Good luck and let me know how you make out.
- Dim intNoOfTips As Integer
-
Dim intLowerbound As Integer, intUpperbound As Integer
-
Dim intRandomTipNo As Integer
-
Dim strRandomTip As String
-
-
Randomize
-
-
intNoOfTips = DCount("*", "tblTips")
-
-
intLowerbound = 1
-
intUpperbound = intNoOfTips
-
-
intRandomTipNo = Int((intUpperbound - intLowerbound + 1) * Rnd + intLowerbound)
-
-
'The Tip itself
-
strRandomTip = DLookup("[Tip]", "[tblTips]", "[TipID]=" & intRandomTipNo)
-
MsgBox strRandomTip