Dim cnnstr1 As String
Dim str As String
Dim cnn2 As ADODB.Connection
' ///////////////
text1.text="处理时间较长,请耐心等候"
'*************************************
bnet = MsgBox("处理时间较长,请耐心等候", vbOKOnly, "数据备份")
If bnet = 1 Then
ProgressBar1.Visible = True
Set cnn1 = New ADODB.Connection
cnn1.CursorLocation = adUseClient
cnn1.ConnectionTimeout = 30
cnn1.Mode = adModeReadWrite
cnnstr1 = "PROVIDER=Microsoft.Jet.OLEDB.4.0;data source=" & App.Path & "\magic.mdb"
cnn1.ConnectionString = cnnstr1
cnn1.Open
Set rs = New ADODB.Recordset
rs.Open "SELECT word,code,cp,cp-ycp FROM usering where cp" & " - " & " ycp<>0", cnn1, adOpenStatic, adLockOptimistic
If rs.EOF = False Then
ProgressBar1.Value = 0
ProgressBar1.Min = 0
rs.MoveLast
ProgressBar1.Max = rs.RecordCount
num_processed = rs.RecordCount
rs.MoveFirst
End If
'*************************************
On Error GoTo MiscError
' Open the output file.
fnum = FreeFile
file_name = App.Path & "\magic.txt"
Open file_name For Output As fnum '打开文件,准备写文件
'*****************************************************************
'取记录总数,并给进度条
' Start with the names of the fields.
num_fields = rs.Fields.Count '字段的数量
' Process the records.
Do While Not rs.EOF
' num_processed = num_processed + 1
For i = 0 To num_fields - 1
field_value = rs.Fields(i).Value
Print #fnum, field_value & _
Space$(1);
Next i
Print #fnum, ""
rs.MoveNext
ProgressBar1.Value = ProgressBar1.Value + 1
Loop
' Close the file and database.
rs.Close
cnn1.Close
Close fnum
bnet = MsgBox("共有 " & _
Format$(num_processed) & " 条记录被备份到" & App.Path & "\magic.txt中", vbOKOnly, "数据备份")
If bnet = 1 Then
ProgressBar1.Visible = False
End If
Exit Sub
MiscError:
MsgBox "Error " & Err.Number & vbCrLf & Err.Description
End If text1.text="处理时间较长,请耐心等候" 并不在开始的时候执行,总是在下面的完成后才看到结果。
Dim str As String
Dim cnn2 As ADODB.Connection
' ///////////////
text1.text="处理时间较长,请耐心等候"
'*************************************
bnet = MsgBox("处理时间较长,请耐心等候", vbOKOnly, "数据备份")
If bnet = 1 Then
ProgressBar1.Visible = True
Set cnn1 = New ADODB.Connection
cnn1.CursorLocation = adUseClient
cnn1.ConnectionTimeout = 30
cnn1.Mode = adModeReadWrite
cnnstr1 = "PROVIDER=Microsoft.Jet.OLEDB.4.0;data source=" & App.Path & "\magic.mdb"
cnn1.ConnectionString = cnnstr1
cnn1.Open
Set rs = New ADODB.Recordset
rs.Open "SELECT word,code,cp,cp-ycp FROM usering where cp" & " - " & " ycp<>0", cnn1, adOpenStatic, adLockOptimistic
If rs.EOF = False Then
ProgressBar1.Value = 0
ProgressBar1.Min = 0
rs.MoveLast
ProgressBar1.Max = rs.RecordCount
num_processed = rs.RecordCount
rs.MoveFirst
End If
'*************************************
On Error GoTo MiscError
' Open the output file.
fnum = FreeFile
file_name = App.Path & "\magic.txt"
Open file_name For Output As fnum '打开文件,准备写文件
'*****************************************************************
'取记录总数,并给进度条
' Start with the names of the fields.
num_fields = rs.Fields.Count '字段的数量
' Process the records.
Do While Not rs.EOF
' num_processed = num_processed + 1
For i = 0 To num_fields - 1
field_value = rs.Fields(i).Value
Print #fnum, field_value & _
Space$(1);
Next i
Print #fnum, ""
rs.MoveNext
ProgressBar1.Value = ProgressBar1.Value + 1
Loop
' Close the file and database.
rs.Close
cnn1.Close
Close fnum
bnet = MsgBox("共有 " & _
Format$(num_processed) & " 条记录被备份到" & App.Path & "\magic.txt中", vbOKOnly, "数据备份")
If bnet = 1 Then
ProgressBar1.Visible = False
End If
Exit Sub
MiscError:
MsgBox "Error " & Err.Number & vbCrLf & Err.Description
End If text1.text="处理时间较长,请耐心等候" 并不在开始的时候执行,总是在下面的完成后才看到结果。
所以需要在这句之后加上一个DOEVENTS来使它响应。
...
text1.text="..."
DoEvents
...
就可以了
建议你使用label控件。
当然,直接用一个MSGBOX也可以,缺点就是会打断程序的运行。
Text1.Refresh '强制刷新或
DoEvents '给操作系统让出时间处理各种事务