I am using VB to accessing data from Excel and i need to refresh/update the data constantly. Pls help.
Thanks
Printable View
I am using VB to accessing data from Excel and i need to refresh/update the data constantly. Pls help.
Thanks
Uhh... help in what way? What are you having a problem with? Which bit specifically is causing you a problem?
What about a timer control on your form, set this to seconds and call the update every 2 secs?
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
------------------------------------------------------------
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:
In order to stop the update loop, set Continue to False in another subroutine.Code:Continue = True
While Continue
UpdateForm 'You have a procedure called
'UpdateForm which will update your form
DoEvents 'Check for new events
Wend
How's that?
Can you pls provide more details on how should go about inserting the codes.. Thanks
You should be able to get away with using your code:
Hope this helps ;)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
[Edited by alex_read on 11-23-2000 at 04:21 AM]
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
-----------------------------------------------
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.
what do u mean.. can u pls elaborate... Thanks
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 :
Which makes it nicer, easier & faster for us to look at & answer ;) - For more info on this, look at:Code:Private sub Command1_click()
text1.text = "hello world"
End Sub
http://forums.vb-world.net/index.php?action=bbcode
- Harry, how did you write that one in without the post turning into code???? :cool: )