Private Sub Command1_Click()
Dim conn As ADODB.Connection
Dim rs As ADODB.Recordset
Dim strSql As String
Set conn = OpenConnForAccess(App.Path & "\test.mdb")
strSql= "insert into testtab(姓名,年龄,性别,电话,住址) values("
for i = 0 to 4
s=trim(addtxt(i).text)
if s="" then s="无内容"
strSql=strSql & "'" & s & "',"
next i
mid(strSql,len(strSql),1)=")"
RunTrans strSql,conn
end sub
Public Function OpenConnForAccess(ByVal FileName As String) As ADODB.Connection
Dim AdoConn As New ADODB.Connection
With AdoConn
.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & FileName & ";Persist Security Info=False"
.Open
End With
Set OpenConnForAccess = AdoConn
End Function
Public Function RunTrans(ByVal tranSql As String, ByVal AdoConn As ADODB.Connection)
With AdoConn
.BeginTrans
.Execute tranSql
.CommitTrans
End With
End Function