Option Explicit
Global cnn As New ADODB.Connection
Global Rs As New ADODB.Recordset
Global cnt As String
Public Function ConnectToServer() As Boolean
Set Rs = New ADODB.Recordset
cnn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.3.51;" & _
"Persist Security Info=False;" & "Data Source =E:\db1.mdb;" & _
"mode=ReadWrite"
cnn.openRs.open
Rs.movelast
If Rs.EOF Then
Rs.movefirstEnd If
    Randmize
    Rs.MaxRecords = 5
    Rs.Move Int(Rnd() * (Rs.recordcount + 1))
    
    cnt = Rs.Fields("content").Value
    ConnectToServer = True
    
End Function
怎么说用户定义类型未定义呀?
请给修改一下,多谢了!

解决方案 »

  1.   


    Option Explicit
    Global cnn As New ADODB.Connection
    Global Rs As New ADODB.Recordset
    Global cnt As String
    Public Function ConnectToServer() As Boolean
    Set Rs = New ADODB.Recordset
    cnn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.3.51;" & _
    "Persist Security Info=False;" & "Data Source =E:\db1.mdb;" & _
    "mode=ReadWrite"
    cnn.openRs.open "select * from xxxx where xxxx"
    Rs.movelast
    If Rs.EOF Then
    Rs.movefirstEnd If
        'Randmize
        Rs.MaxRecords = 5
        Rs.Move Int(Rnd() * (Rs.recordcount + 1))
        
        cnt = Rs.Fields("content").Value
        ConnectToServer = True
        
    End Function
      

  2.   

    修改后变量cnt的值怎么为空呀?
    还请高手指教,谢谢!
      

  3.   

    cnto 为空?你调试看看啊.从你程序上看好像没问题
    对了,Rs.MaxRecords = 5 这是干嘛用的?
      

  4.   

    楼上你好,首先感谢您的关注
    我是想用Rs.MaxRecords = 5 只返回数据库里的5条记录呀
    刚才调试了,弹出对话框 说有不可识别的数据库格式‘E:\db1.mdb;’?
    请问您知道是怎么回事吗?
    谢谢!