我学作做的一个数据库查询窗体,打开窗体时有一个执行代码Stpath = "\\sy2\yt\CKD.mdb"是从网上邻居上的另一台电脑的数据库文件获得数据,一但这台电脑没开机,我在打开窗体时就死机,不知道有什么办法解决这个问题,最好用一个引用一个判断,如果路径不存在能自动退出执行.谢谢各位老师多费的心了,谢谢!!!!!!!!!! 以下是运行窗体的全部代码 Private Sub UserForm_Initialize() '窗体加载 On Error Resume Next TextBox4.Text = "0" TextBox5.Text = CStr(Year(Date) & Format(Month(Date), "00") & Format(Day(Date), "00")) Stpath = "\\sy2\yt\CKD.mdb" CNN.Open "Provider=Microsoft.Jet.OLEDB.4.0;" & _ "Data Source=\\sy2\yt\CKD.MDB; " & _ "Jet OLEDB:Engine Type=4" & ";Jet OLEDB:Database Password=8600796*" 'Open "provider=Microsoft.jet.OLEDB.4.0;data source=" & Stpath SQL = "Select distinct 客户 from mxb" RST.Open SQL, CNN, adOpenKeyset, adLockOptimistic Do Until RST.EOF ComboBox1.AddItem RST("客户") RST.MoveNext Loop RST.Close OptionButton1.Value = False OptionButton2.Value = False ListView1.ColumnHeaders.Clear ListView1.ListItems.Clear ListView1.View = lvwReport ListView1.FullRowSelect = True ListView1.Gridlines = True On Error Resume Next strSQL = "SELECT ID,品名,规格及型号,数量 FROM MXB" strSQL = strSQL & " where ID='" & ComboBox1.Value & "'" RST1.Open strSQL, CNN, adOpenKeyset, adLockOptimistic ListView1.ListItems.Clear ListView1.ColumnHeaders.Clear ListView1.ColumnHeaders.Add , , "行", 30 ListView1.ColumnHeaders.Add , , "ID", 50 ListView1.ColumnHeaders.Add , , "日期", 50 ListView1.ColumnHeaders.Add , , "品名", 70 ListView1.ColumnHeaders.Add , , "规格及型号", 70 ListView1.ColumnHeaders.Add , , "数 量", 50 ListView1.ColumnHeaders.Add , , "单 价", 45 ListView1.ColumnHeaders.Add , , "金 额", 60 ListView1.ColumnHeaders.Add , , "客户", 120 ListView1.ColumnHeaders.Add , , "结算方式", 120 For i = 2 To 6 ListView1.ColumnHeaders(i).Alignment = lvwColumnCenter Next i 'ListView1.ColumnHeaders(7).Alignment = lvwColumnRight ListView1.ColumnHeaders(8).Alignment = lvwColumnRight ListView1.ColumnHeaders(9).Alignment = lvwColumnCenter ListView1.ColumnHeaders(10).Alignment = lvwColumnCenter RST1.Close End Sub |