📄 modconexion.bas
字号:
Attribute VB_Name = "modconexion"
Option Explicit
Public strFechaPrincipal As String
Public goConexion As Connection
Public Mensaje
Public Function Conectar() As Boolean
On Error GoTo va
goConexion.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Persist Security Info=False;Data Source=" & App.Path & "\bd.mdb"
goConexion.Open
Exit Function
va:
Mensaje = "Salto Inesperado al conectar" & Err.Description
MsgBox Mensaje
End Function
Public Sub main()
Set goConexion = New Connection
If Conectar = True Then
Form1.Show
Else
Call MsgBox(Mensaje, vbCritical)
End If
End Sub
Public Function str2Campo(ByVal strValor As String) As String
If Trim(strValor) = vbNullString Then
str2Campo = "Null"
Else
str2Campo = "'" & strValor & "'"
End If
End Function
Public Function Campo2Num(ByVal varParm As Variant) As Double
If IsNull(varParm) Then
Campo2Num = 0
Else
Campo2Num = Val(varParm)
End If
End Function
Public Function Campo2Str(ByVal varParm As Variant) As String
If IsNull(varParm) Then
Campo2Str = vbNullString
Else
Campo2Str = CStr(varParm)
End If
End Function
Public Function str2Fecha(ByVal strValor As String) As String
If Trim(strValor) = vbNullString Then
str2Fecha = "Null"
Else
str2Fecha = "#" & strValor & "#"
End If
End Function
Public Function FechaSQL(ByVal vFecha As String) As String
On Local Error GoTo SQLDateValErr
If IsDate(vFecha) Then
FechaSQL = "#" & Format$(vFecha, "dd/mm/yyyy") & "#"
Else
FechaSQL = vFecha
End If
'
Exit Function
'
SQLDateValErr:
' Si hay error, la fecha por defecto 1-Ene-1980
Err = 0
FechaSQL = "#1980/01/01#"
End Function
Public Function HoraSQL(ByVal vFecha As String) As String
On Local Error GoTo SQLDateValErr
If IsDate(vFecha) Then
HoraSQL = "#" & Format$(vFecha, "hh:mm:ss") & "#"
Else
HoraSQL = vFecha
End If
'
Exit Function
'
SQLDateValErr:
' Si hay error, la fecha por defecto 1-Ene-1980
Err = 0
HoraSQL = "#00:00:00#"
End Function
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -