簡體   English   中英

這個VBA代碼有什么問題

[英]What is wrong with this VBA Code

請告訴我這段代碼有什么問題。 它顯示錯誤...“rowsourcetype屬性必須設置為值列表才能使用此”

Private Sub Form_Load()
     Dim db As DAO.Database
     Dim rs As DAO.Recordset
     Dim strSQL As String, strItem As String

    strSQL = "SELECT CustomerID, CompanyName FROM Customers"
    Set db = CurrentDb
    Set rs = db.OpenRecordset(strSQL)
    Do Until rs.EOF
         strItem = rs.Fields("CustomerID").Value & ";" _
         & rs.Fields("CompanyName").Value
    Me.List1.AddItem strItem      ' Row Source Type must be Value List
    rs.MoveNext

    Loop
    rs.Close
    Set rs = Nothing
    Set db = Nothing
    End Sub

轉到列表項的屬性,在數據中找到屬性“行源類型”並將其設置為“值列表”。 或者你可以通過推桿在代碼中做

Me.Liste3.RowSourceType = "Value List"

Dim strSQL As String, strItem As String之后的代碼Dim strSQL As String, strItem As String

希望這可以幫助! 馬克斯

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM