I have a database which I developed for a church. But I will like to have some Bible verses display on the forms at random .
Is this possible is access?
If it is, how will that be done?
I have a database which I developed for a church. But I will like to have some Bible verses display on the forms at random .
Is this possible is access?
If it is, how will that be done?
Your table of verses should have an autonumber PK id field. Use the random function (Rnd) to generate a number between 1 (if that's the lowest ID) and some higher number. If your count of verse records will remain static, you could base the function on that number. If you're going to add records (verses) you'll need to get a count of the records in the table and pass that value to Rnd. If the forms have records that have nothing to do with the verse, then you'll have to use a form textbox whose control source is set via code by using DLookup function. It would return the verse whose ID corresponds to what the Rnd function calculates. You'll also need an event to trigger a control update - probably the Timer event, which is in milliseconds.
The more we hear silence, the more we begin to think about our value in this universe.
Paraphrase of Professor Brian Cox.
Can you give a practical example so I can understand you betterYour table of verses should have an autonumber PK id field. Use the random function (Rnd) to generate a number between 1 (if that's the lowest ID) and some higher number. If your count of verse records will remain static, you could base the function on that number. If you're going to add records (verses) you'll need to get a count of the records in the table and pass that value to Rnd. If the forms have records that have nothing to do with the verse, then you'll have to use a form textbox whose control source is set via code by using DLookup function. It would return the verse whose ID corresponds to what the Rnd function calculates. You'll also need an event to trigger a control update - probably the Timer event, which is in milliseconds.
Of what? Rnd, DLookup, autonumber PK, getting a record count, Timer event, the whole thing? I don't have a working example if that's what you're asking for. Maybe someone will have a better idea for an approach because that one has several elements to it but I'm sure it would work.Can you give a practical example so I can understand you better
The more we hear silence, the more we begin to think about our value in this universe.
Paraphrase of Professor Brian Cox.
@Isaldogs has a scrolling demonstration DB that you could put up in a disabled textbox, the width of the form ?
Use that with Micron's random suggestion to select a quote?
Please use # icon on toolbar when posting code snippets.
Cross Posting: https://www.excelguru.ca/content.php?184
Debugging Access: https://www.youtube.com/results?sear...bug+access+vba
Figured I'd play.
tblVerses fields: VerseID | Verse; ten records with autonumber PK from 1 to 10
frmVerses with txtVerse textbox; timer event of 10000
EDIT - depending on circumstances, might need to deselect text. Since I only have one control on this test form, the text is highlighted. If that occurs then addCode:Private Sub Form_Timer() Dim i As Long, lngID As Long i = DCount("*", "tblVerses") lngID = ((i - 1 + 1) * Rnd + 1) Me.txtVerse = DLookup("Verse", "tblVerses", "VerseID=" & lngID) End Sub
Me.txtVerse.SelLength = 0
I find the execution stops cursor flashing for about 3 seconds although the event completes on time. Perhaps moving the variables onto the form declaration section would fix that (they wouldn't have to calculate every 10 seconds). Will play some more.
The more we hear silence, the more we begin to think about our value in this universe.
Paraphrase of Professor Brian Cox.
Did you look at the link I provided earlier?
Anyway, here's a simple example based on an existing rich text example app of mine
The form you want is frmRandomText.
EDIT: Just read Micron's last reply. Instead of a command button, you could use a timer event as he suggested. However, as noted, timer events can cause flickering
This makes no difference to cursor behaviour in my test
Developer would have to test effect on user's ability to properly interact with form.Code:Option Compare Database Option Explicit Dim i As Long Private Sub Form_Open(Cancel As Integer) i = DCount("*", "tblVerses") End Sub Private Sub Form_Timer() Dim lngID As Long Randomize lngID = ((i - 1 + 1) * Rnd + 1) Me.txtVerse = DLookup("Verse", "tblVerses", "VerseID=" & lngID) Me.txtVerse.SelLength = 0 End Sub
The more we hear silence, the more we begin to think about our value in this universe.
Paraphrase of Professor Brian Cox.
Did you look at the link I provided earlier?
Anyway, here's a simple example based on an existing rich text example app of mine
The form you want is frmRandomText.
EDIT: Just read Micron's last reply. Instead of a command button, you could use a timer event as he suggested. However, as noted, timer events can cause flickering
The timer event is somehow conflicting with another timer event I have here. But let me play around it to see a way around
You can only have one timer event per form though it is possible you may be able to add the code to your existing timer event code.
However, it is more likely that the answer is no.
One way to get around that would be to put the verse on a subform.
The more we hear silence, the more we begin to think about our value in this universe.
Paraphrase of Professor Brian Cox.
Well, the subform and the timer event seems not to work the way I want it. So I will go be Isladogs uploaded file and modify it a little bit to meet my needs.
Thanks so much to you all for your time and efforts
Noted Man
I really appreciate your time and efforts