J
JohnC
Would you like to display a pun, remark, etc that is randomly selected from
a table when a form loads? This example assumes that when your application
is launched, a startup form loads and then a main form.
<< In the OnOpen event of the startup form add this function name: >>>
Remark
<< Add the following to the declarations section of a standard module. >>>
Public g_strRemark As String
<< Create a standard module called Remark >>>
Public Function Remark() As String
Dim dbs As Database
Dim dynRemarks As DAO.Recordset
Dim intTotalRecords As Integer
Dim iRandomNumber As Integer
Set dbs = CurrentDb
Set dynRemarks = dbs.OpenRecordset("usysStartupRemark", dbOpenDynaset)
Randomize
dynRemarks.MoveLast
intTotalRecords = dynRemarks.RecordCount
iRandomNumber = Int((intTotalRecords * Rnd) + 1)
dynRemarks.AbsolutePosition = iRandomNumber - 1
g_strRemark = dynRemarks!Remark
dynRemarks.Close
dbs.Close
End Function
<< Create a table. >>
Table Name: usysStartupRemark
1 field
Field name: REMARK
Field size: 255
Datatype: Text
<< Enter Puns, remarks, whatever, into the usysStartupRemark table >> <<
Examples >>
Show me a piano falling down a mineshaft and I'll show you A-flat minor.
Pencils could be made with erasers at both ends, but what would be the
point?
Two peanuts were walking in a tough neighborhood and one of them was
a-salted.
<<< Add a label on the form that you want the remark >>
Lable name: lblRemark
<<< In the OnOpen event of the form that you want the random remark to
display enter: >>
Me.lblRemark.Caption = g_strRemark
<<< That should do it. I have this running on a FE/BE database. I put the
usysStartupRemark table in the FE to ensure no delay in obtaining the
remark. John>>
a table when a form loads? This example assumes that when your application
is launched, a startup form loads and then a main form.
<< In the OnOpen event of the startup form add this function name: >>>
Remark
<< Add the following to the declarations section of a standard module. >>>
Public g_strRemark As String
<< Create a standard module called Remark >>>
Public Function Remark() As String
Dim dbs As Database
Dim dynRemarks As DAO.Recordset
Dim intTotalRecords As Integer
Dim iRandomNumber As Integer
Set dbs = CurrentDb
Set dynRemarks = dbs.OpenRecordset("usysStartupRemark", dbOpenDynaset)
Randomize
dynRemarks.MoveLast
intTotalRecords = dynRemarks.RecordCount
iRandomNumber = Int((intTotalRecords * Rnd) + 1)
dynRemarks.AbsolutePosition = iRandomNumber - 1
g_strRemark = dynRemarks!Remark
dynRemarks.Close
dbs.Close
End Function
<< Create a table. >>
Table Name: usysStartupRemark
1 field
Field name: REMARK
Field size: 255
Datatype: Text
<< Enter Puns, remarks, whatever, into the usysStartupRemark table >> <<
Examples >>
Show me a piano falling down a mineshaft and I'll show you A-flat minor.
Pencils could be made with erasers at both ends, but what would be the
point?
Two peanuts were walking in a tough neighborhood and one of them was
a-salted.
<<< Add a label on the form that you want the remark >>
Lable name: lblRemark
<<< In the OnOpen event of the form that you want the random remark to
display enter: >>
Me.lblRemark.Caption = g_strRemark
<<< That should do it. I have this running on a FE/BE database. I put the
usysStartupRemark table in the FE to ensure no delay in obtaining the
remark. John>>