|
-
Nov 22nd, 2000, 02:57 AM
#1
Thread Starter
Member
I am using VB to accessing data from Excel and i need to refresh/update the data constantly. Pls help.
Thanks
-
Nov 22nd, 2000, 03:29 AM
#2
Frenzied Member
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."
-
Nov 22nd, 2000, 08:54 AM
#3
What about a timer control on your form, set this to seconds and call the update every 2 secs?
-
Nov 23rd, 2000, 01:15 AM
#4
Thread Starter
Member
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
------------------------------------------------------------
-
Nov 23rd, 2000, 02:47 AM
#5
Frenzied Member
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."
-
Nov 23rd, 2000, 03:45 AM
#6
Thread Starter
Member
Can you pls provide more details on how should go about inserting the codes.. Thanks
-
Nov 23rd, 2000, 04:12 AM
#7
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]
-
Nov 23rd, 2000, 04:24 AM
#8
Thread Starter
Member
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
-----------------------------------------------
-
Nov 23rd, 2000, 08:54 AM
#9
Frenzied Member
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."
-
Nov 24th, 2000, 01:03 AM
#10
Thread Starter
Member
what do u mean.. can u pls elaborate... Thanks
-
Nov 24th, 2000, 03:43 AM
#11
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|