📄 module1.bas
字号:
Attribute VB_Name = "Module1"
Public rs As adodb.Recordset
Public Function ExecuteSQL(ByVal sql As String) As adodb.Recordset
Dim cnn As adodb.Connection
Dim rst As adodb.Recordset
Dim sTokens() As String
On Error GoTo ExecuteSQL_Error '//设置错误捕获
sTokens = Split(sql) '//分割字符串
Set cnn = New adodb.Connection
cnn.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & App.Path & "\data\kq.mdb;"
If InStr("INSERT,DELETE,UPDATE", UCase$(sTokens(0))) Then
cnn.Execute sql
Else
Set rst = New adodb.Recordset
rst.CursorLocation = adUseClient
rst.Open Trim$(sql), cnn, adOpenKeyset, adLockOptimistic
Set ExecuteSQL = rst
End If
ExecuteSQL_Exit:
Set rst = Nothing
Set cnn = Nothing
Exit Function
ExecuteSQL_Error:
Debug.Print Err.Description
Resume ExecuteSQL_Exit
End Function
'将Null结尾字符串转换到VB字符串
Public Function LPSTRToVBString$(ByVal s$)
Dim nullpos&
nullpos& = InStr(s$, Chr$(0))
If nullpos > 0 Then
LPSTRToVBString = Left$(s$, nullpos - 1)
Else
LPSTRToVBString = ""
End If
End Function
Public Function RemoveBackslash(sFlName As String) As String
Dim i As Integer
i = Len(sFlName)
If i <> 0 Then
If Right$(sFlName, 1) = "\" Then
RemoveBackslash = Left$(sFlName, i - 1)
Else
RemoveBackslash = sFlName
End If
Else
RemoveBackslash = ""
End If
End Function
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -