Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Wanet Telecoms Ltd on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Scrolling Text In Form

Status
Not open for further replies.

roystreet

Programmer
Oct 12, 2000
146
US
Hello,
I searched for Scrolling Text In Form & found a thread where someone asked the same question & they received a reply with a link to a FAQ that answered it. But when I click on it there is no longer any FAQ that answers this question....

I want to have a form that displays credits and other information on a form, but I want it to scroll. So that the text scrolls upward & at a reasonable speed. I searched this website pretty good & I can't find the answer, so I'm asking here.

Thanks,
---roystreet
 
that would be

faq181-86

it is under microsoft access other topics faq

the code scrolls one letter at a time but can be easily adjusted to do one line at a time

good luck

also newer versions of access have a marquee control.
 
the link above seemed to have stopped working here is the text from the FAQ

Step1 create an unbound textbox or a label
Step2 Paste this code in the forms code section

//////////////////////////////////
'start paste
Private Static Function Scrolltext(Strfield As String) As String
‘call from on timer event
Dim astr As Integer
Dim TextLen As Integer

astr = astr + 1
TextLen = Len(Strfield)
If astr >= TextLen Then astr = 1
Scrolltext = Mid([Strfield], astr, Len([Strfield])) & " " & Left([Strfield], astr)

End Function

end paste
////////////////////////////////////
Step 3 Call the function from the forms on timer event
For any text
Me!text1.text = Scrolltext(“Hello World”) ‘Refer to the unbound text box

For a label
Me.label1.caption = Scrolltext(“Hello World”)

To use data from a field

Me.text1.text= Scrolltext(me.fieldname) or me.label1.caption = scrolltext(me.fieldname)

Step 4 set the forms timer interval. The higher the number the slower it scrolls around 100 is usually good enough

Step 5 Open the form then sit back and watch your text scroll by.
 
gol4,
I would love for it to be simple, but I am having problems here & maybe it's just me....
I created a unbound text box & named it scroller.
Then I went to view & selected code so that I could view the code for the form. Then I placed the below code into it:
Code:
Private Static Function Scrolltext(Strfield As String) As String
'call from on timer event
Dim astr As Integer
Dim TextLen As Integer
   
   astr = astr + 1
   TextLen = Len(Strfield)
   If astr >= TextLen Then astr = 1
    Scrolltext = Mid([Strfield], astr, Len([Strfield])) & " " & Left([Strfield], astr)
                                 
   End Function



Private Sub Form_Timer()
Me!scroller.text =  Scrolltext(“Hello World”) ‘Refer to the unbound text box

End Sub

Private Static Function SpellOut(strMessage As String) As String

Dim iCount As Integer
Dim iLen As Integer
                                 
   iLen = Len(strMessage)
   If iCount >= iLen Then iCount = 1
    
   SpellOut = Left(strMessage, iCount)
   iCount = iCount + 1
    
    End Function

When I pasted the
Code:
 Me!scroller.text =  Scrolltext(“Hello World”)
into the ontimer event it made that line of code red. When I opened the form, it waited until the timer function would take effect & then it would open up the debugger & tell me there was a syntax error. It would highlight the above code that was red. What am I doing wrong? This form only has this one field & nothing else.

Thanks,
---roystreet
 
yea I was able to reproduce that

I changed the
Me!scroller.text = Scrolltext(“Hello World”) two strange lookg qoutes to double quotes and it worked

Me!scroller.Text = Scrolltext("Hello World")

dont forget to set the timer interval
 
gol4,

It's working pretty good, but...The text only goes to the middle of the text box?? Not sure why?? Also, now I'm still fairly new at code - How do I make it do one line at a time as you said I could do?

Thanks.
 
Its only going to the middle of the textbox because "Hello world is a very short string. Try a longer string.

To get it to do a line at a time you will need to better understand what the code is doing here and adjust it based on the string you are passing it.
Assume you have a testbox showing 50 characters across you would need to adjust the code so it drops the first 50 characters. To maintain the lines you may even have to put in some code to look for line breaks. Depending on how the string you are passing it is set up

I'm in the middle of a tight project or I would be glad to elaborate further. Sorry

 
Just so you know, since I have a longer string it's going all of the way across. I still can't figure out how to do lines. My preference would be the each line of text would move upward instead of to the left or to the right. But I still like this style. I've stopped working on this area for right this minute. Whenever you have time I'd appreciate your help. But please don't pull yourself away from your big project, I know mine is a small one. I know how it feels to have a BIG project.

Thanks,
---roystreet
 
RoyStreet,
I did not say it was a Big project just a tight one. Had to meet some deadlines
Now for the longer explanation. To make it scroll you need to understand that this code is not actually scrolling thru the text box it is taking the string and changing how it appears
So "Hello world" becomes "ello world H" then "llo World He" etc.
The code steps thru the string 1 letter at a time thus astr variable increases by 1. The mid function gets all the characters 1 to the right and the left function returns 1 to the left then 2-3-4 once it reaches the end of the string then it is reset to 1.
You want to go one line at a time so you need to set the astr variable to the length of the line
So instead of the "hello world example" you want

Line1 Line2
Line2 to become Line3
Line3 Line1

The the end of your lines will determine how you set this variable
As a example I added a label to a new form named it label2
Typed in this is line1 shift-enter this is line2 shift-enter etc till I had 10 lines filling the label

I then put this code in the forms on timer event

Private Sub Form_Timer()
Dim astr As Integer
Dim Strfield As String
Strfield = Me.Label2.Caption
astr = InStr(Strfield, Chr$(10))
Me.Label2.Caption = Mid([Strfield], astr + 1) & Left([Strfield], astr)
End Sub

Set the timer interval to 500 and it scrolled line by line

I am using the instr function to look for line feeds setting astr to that then using mid and left to build the string

Hopefully this gets you going. Good luck




 
Here is code I got here on Tek-tips, but unfortunatley I can't remember the keywords I typed in that brought me across this. I know you can reverse how the text is moving, but I don't remember how they wrote it.

'Put this code in the Form Timer & set to anywere between 100-250 - you can play around with it to find out what works best. If you are going to use a label, put a caption on your label in the properties and use the .Caption below. If you are going to use a textbox use .value.

Private Sub Form_Timer()
Me.(your label name).Caption = basScrolltext(Me.(your label name).Caption)
End Sub

'Add this code into the form code anywhere:
Private Function basScrolltext(Strfield As String) As String
basScrolltext = Mid(Strfield, 2, Len(Strfield) - 1) & Left(Strfield, 1)
End Function


If anyone knows how to change the direction of how the text reads please let me know. I know instead of Mid you can use Right, but it has to be written differently and I don't remember how it was written.

Thanks and Hope this works,
Sherry

 
I found the thread: thread702-255626 This should answer your questions and it doesn't stop in the middle.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top