vb编程实例讲解、告诉我一些简单的vb编程代码?( 九 )


For Each fld In rst.Fields
If fld.Name = ctl.Name Then
ctl = fld.DefaultValue
Exit For
End If
Next
End If
Next
rst.Close
Set rst = Nothing
End Function
Public Function SaveData(strSQL As String)
'On Error GoTo Err_SaveData
Dim rst As DAO.Recordset
Dim ctl As Control
Dim fld As Object
If MsgBox("您确认要保存吗?", vbOKCancel + vbInformation, "提示!!!") = vbOK Then
If AddTag = True Then
Set rst = CurrentDb.OpenRecordset(strSQL, , dbReadOnly)
rst.AddNew
Else
Set rst = CurrentDb.OpenRecordset(strSQL)
rst.Edit
End If
For Each ctl In ctlFormName
'Debug.Print ctl.Name
If Not (TypeOf ctl Is Label Or TypeOf ctl Is CommandButton) Then
For Each fld In rst.Fields
'Debug.Print fld.Name
If fld.Name = ctl.Name Then
rst(fld.Name) = ctl
Exit For
End If
Next
End If
Next
rst.Update
rst.Close
Set rst = Nothing
MsgBox "数据保存成功!", vbInformation, "提示!!!"
End If
Exit_SaveData:
Set rst = Nothing
Exit Function
Err_SaveData:
If Err = 3022 Then
MsgBox "同一节点下不能存在相同的子节点,请修改后再点保存!", vbCritical, "警告!!!"
Else
MsgBox Err.Source & " #" & Err & vbCrLf & vbCrLf & Err.Description, vbCritical
On Error Resume Next
End If
Resume Exit_SaveData
End Function
Public Function DelSource(Form As Form)
Dim ctl As Control
Form.RecordSource = ""
For Each ctl In Form
If Not (TypeOf ctl Is Label) Then
ctl.ControlSource = ""
End If
Next
End Function
Public Function DelData(strSQL As String)
Dim rst As New ADODB.Recordset
Dim i As Long
If MsgBox("你确定要删除当前记录吗?", vbOKCancel + vbQuestion, "删除!!!") = vbOK Then
'Debug.Print strSQL
rst.Open strSQL, CurrentProject.Connection, adOpenKeyset, adLockOptimistic
If rst.RecordCount > 0 Then
For i = 1 To rst.RecordCount
rst.Delete
rst.Update
rst.MoveNext
Next
End If
rst.Close
Set rst = Nothing
End If
End Function
关于vb编程实例和vb编程实例讲解的介绍到此就结束了,不知道你从中找到你需要的信息了吗?如果你还想了解更多这方面的信息,记得收藏关注本站 。
查看更多关于vb编程实例的详细内容...
【vb编程实例讲解、告诉我一些简单的vb编程代码?】Tags:vb编程实例vb编程实例讲解


推荐阅读