|
本帖最后由 microyip 于 2020-11-23 11:21 编辑
- Dim cnn As New ADODB.Connection
- Dim rst As New ADODB.Recordset
- Private Sub UserForm_Initialize() '
- Dim sPath As String, sSQL As String, vRS As Variant, vList As Variant, nI As Double
-
- sPath = ThisWorkbook.Path & "\数据库.mdb"
- cnn.Open "provider=Microsoft.jet.OLEDB.4.0;data source=" & sPath
- sSQL = "Select Max([收据编号]) From [资料]"
-
- rst.Open sSQL, cnn, adOpenKeyset, adLockOptimistic
- If Not (rst.EOF And rst.BOF) Then
- vRS = rst.GetRows
- Label5 = Format(Val(vRS(0, 0)) + 1, "00000000")
- Else
- Label5 = "00000001"
- End If
- Label12 = Sheet1.Range("a7")
- Label3 = Sheet1.Range("a6")
- Label4 = Format(Date, "yyyy年mm月dd日")
- rst.Close
- sSQL = "Select distinct 名称 from 款项来源 order by 名称"
- rst.Open sSQL, cnn, adOpenKeyset, adLockOptimistic
- If Not (rst.EOF And rst.BOF) Then
- vRS = rst.GetRows
- ReDim vList(1 To UBound(vRS, 2) + 1)
- For nI = 0 To UBound(vRS, 2)
- If Not IsNull(vRS(0, nI)) Then vList(nI + 1) = vRS(0, nI)
- Next
- ComboBox1.List = vList
- End If
- rst.Close
- cnn.Close
- Set rst = Nothing
- Set cnn = Nothing
- End Sub
复制代码 |
|