Public conn As New ADODB.ConnectionPublic rs As New ADODB.RecordsetPublic addFlag As BooleanPublic Function OpenCn (ByVal Cip As String) As BooleanDim mag As StringOn Error GoTo strerrmagSet conn = New ADODB.Connectionconn.ConnectionTimeout = 25conn.Provider = "sqloledb" conn. Properties ("Data Source"). Value = CIP 'server's name Conn.properties ("Initial Catalog"). Value = "zqoa"' library name 'conn.properties ("Integrated Security). Value =" sspi "' Land type conn.properties ("user ID"). Value = "sa" conn.properties ("password"). Value = "sa" conn.openopencn = trueaddflag = truexit functionstrerrmag: MAG = "Data can't connect" CALL MsgBox (MAG, VBOKONLY, "ERROR: DATA Connect") addflag = false exit functionend function
Public Sub Clocn () on error resume nextif conn.state <> adstateclosed the conn.closset conn = nothingend sub
Public Function openRs (ByVal strsql As String) As Boolean 'connected database records Dim mag As StringDim rpy As BooleanOn Error GoTo strerrmag Set rs = New ADODB.Recordset If addFlag = False Then rpy = True With .ActiveConnection = conn .CursorLocation rs = adUseClient .CursorType = adOpenKeyset .LockType = adLockOptimistic .Open strsql End With addFlag = True openRs = True End 'Exit Functionstrerrmag: mag = "data not connect" Call MsgBox (mag, vbOKOnly, "error: connect") openRs = False End' EXIT FUNCTIONEND FUNCTIONPUBLIC SUB Clors () On Error ResMe nextif rState <> adstateclosed the rs.clonset RS = Nothingend Sub