Results 1 to 11 of 11

Thread: Auto refresh/update data

  1. #1

    Thread Starter
    Member
    Join Date
    Nov 2000
    Posts
    36

    Unhappy

    I am using VB to accessing data from Excel and i need to refresh/update the data constantly. Pls help.

    Thanks

  2. #2
    Frenzied Member HarryW's Avatar
    Join Date
    Jan 2000
    Location
    Heiho no michi
    Posts
    1,827
    Uhh... help in what way? What are you having a problem with? Which bit specifically is causing you a problem?
    Harry.

    "From one thing, know ten thousand things."

  3. #3
    Evil Genius alex_read's Avatar
    Join Date
    May 2000
    Location
    Espoo, Finland
    Posts
    5,538
    What about a timer control on your form, set this to seconds and call the update every 2 secs?

    Please rate this post if it was useful for you!
    Please try to search before creating a new post,
    Please format code using [ code ][ /code ], and
    Post sample code, error details & problem details

  4. #4

    Thread Starter
    Member
    Join Date
    Nov 2000
    Posts
    36
    I need help in how to constantly update the form. Below is my source code...

    ------------------------------------------------------------

    Option Explicit
    'Dim Quit As Integer

    Private Sub Command1_Click()
    Quit = 1
    End
    End Sub

    Private Sub Form_Load()
    Dim count
    Quit = 0
    Do While (Quit <> 1)
    Workbooks.Open "c:\temp.xls"
    Text1.Text = Worksheets("Sheet1").Cells(1, 2).Value
    Text2.Text = Worksheets("Sheet1").Cells(2, 2).Value
    Text3.Text = Worksheets("Sheet1").Cells(3, 2).Value
    Text4.Text = Worksheets("Sheet1").Cells(4, 2).Value
    Text5.Text = Worksheets("Sheet1").Cells(5, 2).Value
    Text6.Text = Worksheets("Sheet1").Cells(6, 2).Value
    Workbooks.Close
    For count = 1 To 6000
    Next count
    Loop
    End Sub

    ------------------------------------------------------------

  5. #5
    Frenzied Member HarryW's Avatar
    Join Date
    Jan 2000
    Location
    Heiho no michi
    Posts
    1,827
    Well Alex's suggestion is one way of doing it. Alternatively, you could keep a loop running all the time while you want your form updated, like this:

    At global scope (ie in a module):
    Code:
    Public Continue As Boolean

    and in your code:
    Code:
    Continue = True
    
    While Continue
    	UpdateForm	'You have a procedure called
    			'UpdateForm which will update your form
    
    	DoEvents	'Check for new events
    Wend
    In order to stop the update loop, set Continue to False in another subroutine.

    How's that?
    Harry.

    "From one thing, know ten thousand things."

  6. #6

    Thread Starter
    Member
    Join Date
    Nov 2000
    Posts
    36
    Can you pls provide more details on how should go about inserting the codes.. Thanks

  7. #7
    Evil Genius alex_read's Avatar
    Join Date
    May 2000
    Location
    Espoo, Finland
    Posts
    5,538
    You should be able to get away with using your code:

    Code:
    Public Continue as string
    
    Private Sub Form_Load() 
      Workbooks.Open "c:\temp.xls" 
      Continue = True
    
      While Continue = true
        Text1.Text = Worksheets("Sheet1").Cells(1, 2).Value 
        Text2.Text = Worksheets("Sheet1").Cells(2, 2).Value 
        Text3.Text = Worksheets("Sheet1").Cells(3, 2).Value 
        Text4.Text = Worksheets("Sheet1").Cells(4, 2).Value 
        Text5.Text = Worksheets("Sheet1").Cells(5, 2).Value 
        Text6.Text = Worksheets("Sheet1").Cells(6, 2).Value 
      Wend
    End Sub
    
    Private Sub Command1_Click() 
        Continue = false
    End Sub
    Hope this helps

    [Edited by alex_read on 11-23-2000 at 04:21 AM]

    Please rate this post if it was useful for you!
    Please try to search before creating a new post,
    Please format code using [ code ][ /code ], and
    Post sample code, error details & problem details

  8. #8

    Thread Starter
    Member
    Join Date
    Nov 2000
    Posts
    36
    Thanks for helping.. i have already solve the problem. Below is my solution...

    -----------------------------------------------
    Option Explicit
    Public Continue As Boolean

    Private Sub Command1_Click()
    Continue = False
    End
    End Sub

    Private Sub Form_Activate()
    While Continue = True
    UpdateForm
    DoEvents 'Check for new events
    Wend
    End Sub

    Sub UpdateForm()
    Workbooks.Open "c:\temp.xls"
    Text1.Text = Worksheets("Sheet1").Cells(1, 2).Value
    Text2.Text = Worksheets("Sheet1").Cells(2, 2).Value
    Text3.Text = Worksheets("Sheet1").Cells(3, 2).Value
    Text4.Text = Worksheets("Sheet1").Cells(4, 2).Value
    Text5.Text = Worksheets("Sheet1").Cells(5, 2).Value
    Text6.Text = Worksheets("Sheet1").Cells(6, 2).Value
    Workbooks.Close
    End Sub

    Private Sub Form_Load()
    Continue = True
    UpdateForm
    End Sub
    -----------------------------------------------

  9. #9
    Frenzied Member HarryW's Avatar
    Join Date
    Jan 2000
    Location
    Heiho no michi
    Posts
    1,827
    That's exactly what I meant

    By the way, you can use code tags to make your code preformatted, like the <PRE> tags in HTML. Put [code] and [/code] around your code.
    Harry.

    "From one thing, know ten thousand things."

  10. #10

    Thread Starter
    Member
    Join Date
    Nov 2000
    Posts
    36
    what do u mean.. can u pls elaborate... Thanks

  11. #11
    Evil Genius alex_read's Avatar
    Join Date
    May 2000
    Location
    Espoo, Finland
    Posts
    5,538

    Lightbulb

    I'll nip in here - sorry HarryW.
    cassandra, HarryW means rather than posts showing up:

    Private sub Command1_click()
    text1.text = "hello world"
    End Sub

    you can get this to appear like this :
    Code:
    Private sub Command1_click()
        text1.text = "hello world"
    End Sub
    Which makes it nicer, easier & faster for us to look at & answer - For more info on this, look at:
    http://forums.vb-world.net/index.php?action=bbcode

    - Harry, how did you write that one in without the post turning into code???? )

    Please rate this post if it was useful for you!
    Please try to search before creating a new post,
    Please format code using [ code ][ /code ], and
    Post sample code, error details & problem details

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width