Scrolling news using a record (1 Viewer)

Merdok

Nerd
Local time
Today, 01:24
Joined
Jul 10, 2003
Messages
52
Hi guys,

Thanks for you help so far, my little application is coming along nicely.

Ok I'm trying to make a scrolling bar which runs along the bottom of the screen which will have text based news in it.

I wish the news to be stored in a table. The user needs to be able to add upto 10 news items (but less if nessecary) and edit them at whim.

I cant figure this one out, I downloaded an example from another website but I couldnt get it to use multiple records (ie it would only use the first record)

I need to be able to format the scroller as well, obviously it needs to fit in with the design of my application but I have certain requirements for the news text as well.. eg:

· News item 1 · News item 2 · News item 3 ·

Any ideas guys?
 

Fizzio

Chief Torturer
Local time
Today, 01:24
Joined
Feb 21, 2002
Messages
1,885
A lot depends on how the scroller works. If it takes the value from the field then you will have to doctor the code a little bit.
You need essentially to create a string variable, (that you can format yourself) by concatenating all the field values. You can do this by using a recordset eg
Code:
Dim rsNewsItems as Dao.Recordset 'Reference to DAO must be selected from Tools->References
Dim strNews as String
set rsNewsItems = CurrentDb.OpenRecordset("tblNews",dbOpenStatic,dbReadOnly)

rsNewsItems.movefirst
Do until rsNewsItems.EOF
strNews = strNews + rsNewsItems("NewsField") + " • "
rsNewsItems.movenext
loop
set rsNewsItems = Nothing

Then in the scroller code, replace the value it uses for the news with strNewsItems

Post the scroller code if you have no joy.
 

Merdok

Nerd
Local time
Today, 01:24
Joined
Jul 10, 2003
Messages
52
Well to be honest, the code I've got isnt really usefull for what I want it for so integrating what you gave me into that would be pointless. :(

It has to look like the attached image really.

Everything else looks like its supposed to :D but not the scroller, whcih is currently at the top, with plain black text on a plain white background (and is updated in the code, not by a record)
 

Attachments

  • mainmenu_layout.jpg
    mainmenu_layout.jpg
    25.5 KB · Views: 509

Fizzio

Chief Torturer
Local time
Today, 01:24
Joined
Feb 21, 2002
Messages
1,885
Can you post the link to the code you are currently using to display the scroller If my solution can not be intergrated, without the source code, makes the task virtually impossible (without building a new scroller):(
 

Merdok

Nerd
Local time
Today, 01:24
Joined
Jul 10, 2003
Messages
52
excellent point... sorry about that :)

Its long though so I'll like a txt file.

Just as a side note, the only modifications I made to this code was adding the refrence to the text box for the scrolling text content (sorry about the poor english there - not enough coffee too much headpain) and i've altered the size to 1280 long (but I'd prefer if I could use percentages instead although I'm not too fussed)

Currently this is held in a form which I hide called frmscrollertext and I'd prefer to just call it FrmNews as this makes things simpler for other people as the table it refrences is called TblNews.

Also is there anyway to change the direction the text is scrolling in?
 

Attachments

  • scroller.txt
    12.2 KB · Views: 696

Fizzio

Chief Torturer
Local time
Today, 01:24
Joined
Feb 21, 2002
Messages
1,885
OK - I see you are using Stephen Lebans Scroller Code - This is useful but has a distinct lack of documentation to help you customise things.

This line (Form_LOad())
' Let's give our Scroller Something to Scroll
Me.txtToBeScrolled = "me.txttobescrolled" can be modified to include the code I gave you

Change it to

Code:
Dim rsNewsItems as Dao.Recordset 'Reference to DAO must be selected from Tools->References
Dim strNews as String
set rsNewsItems = CurrentDb.OpenRecordset("tblNews",dbOpenStatic,dbReadOnly)

rsNewsItems.movefirst
Do until rsNewsItems.EOF
strNews = strNews + rsNewsItems("NewsField") + " • "
rsNewsItems.movenext
loop
set rsNewsItems = Nothing

Me.txtToBeScrolled = strNewsItems

This line
'lngret = apiSetBkColor(hDC, RGB(127, 127, 127)) 'RGB values for the colour you want
sets the colour behind the text (not the scroller box)

To set the text colour use
lngret = apiSetTextColor(hDC, RGB(127, 127, 127))

To position the scroller where you want it I suggest in the hidden form where you have the message textbox, unhide it and place it where you want it on the screen (This makes it moveable if you make the border thin or dialog and ststic if you make the border none)

Change these lines
Code:
    ' These next 2 calls yield Application.hWndAccessApp
    ' lngret = GetParent(Me.hwnd)
    ' lngret = GetParent(lngret)
    ' Or more simply and directly
    ' lngret = SetParent(hWndScroll, Application.hWndAccessApp)
    ' Make this Form the Parent
    ' lngret = SetParent(hWndScroll, Me.hWnd)

[b]to[/b]
    ' These next 2 calls yield Application.hWndAccessApp
    ' lngret = GetParent(Me.hwnd)
    ' lngret = GetParent(lngret)
    ' Or more simply and directly
      lngret = SetParent(hWndScroll, Application.hWndAccessApp)
    ' Make this Form the Parent
      lngret = SetParent(hWndScroll, Me.hWnd)
as this binds the scroller to the form.

This Line (Form_Timer())
lngret = FillRect(hdc, tempRect, hBrush) sets the background colour. hbrush is defined earlier as the constant WHITE_BRUSH so you can enter any value and see what the effect is!

Changing the pixel offset to a negative number scrolls the opposite way but it does it once and then never again:confused:

How does this get you started??
 

Merdok

Nerd
Local time
Today, 01:24
Joined
Jul 10, 2003
Messages
52
Fantastic! The scary part is that most of that made sense to me... must be picking this up! :)

Thanks for you help mate, I'll give that a try!
 

Merdok

Nerd
Local time
Today, 01:24
Joined
Jul 10, 2003
Messages
52
Ok... Once I've updated the code I get this:

"Compile error:

Variable not defined"

And "DbOpenStatic" is hightlighted.

Any Thoughts?
 
Last edited:

Fizzio

Chief Torturer
Local time
Today, 01:24
Joined
Feb 21, 2002
Messages
1,885
Sorry, should be DbOpenSnapshot

(getting my DAO and ADO mixed up again:rolleyes: )
 

ghudson

Registered User.
Local time
Yesterday, 20:24
Joined
Jun 8, 2002
Messages
6,194
Try this sample I just put together. It appears to be a lot simpler than what you are attempting. It uses one table and the table only has one field. A record set is used to create the string for the scrolling text within the form. The form scrolls the text within a label and also along the bottom status bar. Ricky Hicks deserves the credit for his use of the Mid function within a Timer event to create the scrolling effect.

HTH
 

Attachments

  • scrollingmessageboard.zip
    14.6 KB · Views: 901

Fizzio

Chief Torturer
Local time
Today, 01:24
Joined
Feb 21, 2002
Messages
1,885
I like that:) - easier than fiddling on with API calls anyway!
 

Merdok

Nerd
Local time
Today, 01:24
Joined
Jul 10, 2003
Messages
52
no kidding! :)

Cheers lads, I'll try that tomorrow!

AAhh its all coming together! :cool: :D
 

Merdok

Nerd
Local time
Today, 01:24
Joined
Jul 10, 2003
Messages
52
Ok I imported it ok but I'm getting a "type 13 mismatch" error, all the refrences that are ticked in the scroller project are ticked in my project so I am officially stumped.

Any clues?
 

Fizzio

Chief Torturer
Local time
Today, 01:24
Joined
Feb 21, 2002
Messages
1,885
Which line of code is giving you the error?
 

Merdok

Nerd
Local time
Today, 01:24
Joined
Jul 10, 2003
Messages
52
I dont know. A dialoge box pops up with that message saying just that and noot else.

I might be able to figure it out for myself if I had a clue...

I looked at line 13 and this is what I got:

L12| Dim rMessage As Recordset
L13|
L14| Set MyDb = CurrentDb()
 

ghudson

Registered User.
Local time
Yesterday, 20:24
Joined
Jun 8, 2002
Messages
6,194
Does my sample work okay for you? It works okay for me with Access 97.

Are you only having a problem using it within your own db? If so, check you data types are the same, check that your field and table names are the same as in the code.
 

Merdok

Nerd
Local time
Today, 01:24
Joined
Jul 10, 2003
Messages
52
yeah they are... I imported the example you sent and didnt change anything in the table.
 

Sharkiness

Registered User.
Local time
Today, 01:24
Joined
Sep 25, 2008
Messages
31
Try this sample I just put together. It appears to be a lot simpler than what you are attempting. It uses one table and the table only has one field. A record set is used to create the string for the scrolling text within the form. The form scrolls the text within a label and also along the bottom status bar. Ricky Hicks deserves the credit for his use of the Mid function within a Timer event to create the scrolling effect.

HTH

Thanks for this. I have used it in my database based on a field in a particular table with many fields. I get one problem where an error message occurs if there is no data in this field. Is there a way to insert into the code something that will change the scrolling text to 'No Message to Display' if the field is empty?

Cheers
 

vbaInet

AWF VIP
Local time
Today, 01:24
Joined
Jan 22, 2010
Messages
26,374
I don't know what the code looks like but you can use the IIF() function in this format:
Code:
=IIF(Len([FieldName] & "") = 0, "No message to display", "Scrolling text here")
 

Sharkiness

Registered User.
Local time
Today, 01:24
Joined
Sep 25, 2008
Messages
31
I don't know what the code looks like but you can use the IIF() function in this format:
Code:
=IIF(Len([FieldName] & "") = 0, "No message to display", "Scrolling text here")

Code:
Option Compare Database
Option Explicit
Public txtScrollStatus As String
Private Sub Form_Open(Cancel As Integer)

On Error GoTo Err_Form_Open
    
    Dim MyDb As Database
    Dim sMessage As String
    Dim sMessages As String
    Dim rMessage As Recordset
    Set MyDb = CurrentDb()
    sMessage = ""
    sMessages = ""
    sMessages = "SELECT tblAgent.AgentName FROM tblAgent WHERE (((tblAgent.AgentName) Is Not Null));"
    
    Set rMessage = MyDb.OpenRecordset(sMessages)
        rMessage.MoveFirst
    Do Until rMessage.EOF = True
        sMessage = sMessage & Space(10) & rMessage!AgentName
    If Not rMessage.EOF Then rMessage.MoveNext
    
   
    Loop
    TimerInterval = 100
    Me.lMessage.Caption = sMessage
    txtScrollStatus = sMessage
    
    Set MyDb = Nothing
    Set rMessage = Nothing
Exit_Form_Open:
    Exit Sub
Err_Form_Open:
    MsgBox Err.Number & " " & Err.Description
    Resume Exit_Form_Open
End Sub
Private Sub Form_Timer()
On Error GoTo Err_Form_Timer
    
    'Thanks to Ricky Hicks for his excellent use of the Mid function with a timer
    
    Me.lMessage.Caption = Mid(Me.lMessage.Caption, 2, (Len(Me.lMessage.Caption) - 1)) & Left(Me.lMessage.Caption, 1)
    
    SysCmd acSysCmdSetStatus, txtScrollStatus
    txtScrollStatus = Mid(txtScrollStatus, 2, (Len(txtScrollStatus) - 1)) & Left(txtScrollStatus, 1)
    
Exit_Form_Timer:
    Exit Sub
Err_Form_Timer:
    MsgBox Err.Number & " " & Err.Description
    Resume Exit_Form_Timer
    
End Sub

Heres the code, where would I put it?
 

Users who are viewing this thread

Top Bottom