juanr 发表于:2008-02-13 21:36:27
Private Sub saveData()
'新增报销数据子程序
Dim rst As DAO.Recordset
'如果保存时,别的操作员新增了此编号,则生成新的编号
If Acchelp_StrDataIsExist("tblcgdd", "cgddid", Me.cgddid) = True Then
'生成新的编号
AutoMxID
End If
If IsNull(Me.gysid) Then
MsgBox "请选择供应商", vbCritical, "提示"
Me.gysid.SetFocus
Exit Sub
End If
If IsNull(Me.lxr1) Then
MsgBox "请输入联系人", vbCritical, "提示"
Me.lxr1.SetFocus
Exit Sub
End If
If IsNull(Me.dhrq) Then
MsgBox "请输入订货日期", vbCritical, "提示"
Me.dhrq.SetFocus
Exit Sub
End If
If IsNull(Me.zzrq) Then
MsgBox "请输入最早交货日期", vbCritical, "提示"
Me.zzrq.SetFocus
Exit Sub
End If
If IsNull(Me.zcrq) Then
MsgBox "请输入最晚交货日期", vbCritical, "提示"
Me.zcrq.SetFocus
Exit Sub
End If
'如何将焦点转移到子窗体,并运行以下两个IF 语句??????
If IsNull(Me.ljid) Then
MsgBox "请输入零件名称", vbCritical, "提示"
Me.ljid.SetFocus
Exit Sub
End If
If IsNull(Me.sl) Then
MsgBox "请输入零件数量", vbCritical, "提示"
Me.sl.SetFocus
Exit Sub
End If
If MsgBox("您确认要保存吗?", vbOKCancel + vbInformation, "提示") = vbOK Then
'在保存之前刷新窗体
Me.Refresh
'打开tblcgdd表
Set rst = CurrentDb.OpenRecordset("tblcgdd", dbOpenDynaset)
'新增一行数据
rst.AddNew
rst("cgddid") = Me.cgddid
rst("gysid") = Me.gysid
rst("lxr1") = Me.lxr1
rst("cgddrq") = Me.dhrq
rst("zzrq") = Me.zzrq
rst("zcrq") = Me.zcrq
'操作员,czyid的字段大小务必为6,请检查
rst("czyid") = Forms!usysfrmLogin!txtUserName
rst.Update
rst.Close
Set rst = Nothing
If Me.fxsblj = -1 Then
'将tblXsddsblj_temp表中的数据追加到tblXsddsblj表中
DoCmd.SetWarnings False
DoCmd.RunSQL "INSERT INTO tblcgmx SELECT tblcgmx_temp.* FROM tblcgmx_temp;"
End If
'刷新数据,通过重新加载子窗体实现
If IsLoaded("usysfrmMain") Then
DoCmd.Echo False
Forms!usysfrmMain!frmChild.SourceObject = "frmcgdd_child"
DoCmd.Echo True
End If
MsgBox "保存成功!", vbInformation, "提示"
'清空,以便录入新记录
Me.gysid = Null
Me.lxr1 = Null
Me.dhrq = Date
Me.zzrq = Date + 10
Me.zcrq = Date + 25
'让khid获得焦点,不然如果焦点停留在frmChild上,会出错
Me.gysid.SetFocus
'生成新的编号
AutoMxID
If Me.fxsblj = -1 Then
'清空三包零件临时表 tblXsddsblj_temp
DoCmd.SetWarnings False
DoCmd.RunSQL "DELETE tblcgmx_temp.* FROM tblcgmx_temp;"
End If
Me.fxsblj = 0
'子窗体不可新增数据
Me.frmChild.Form.AllowAdditions = False
Me.gysid.SetFocus
End If
End Sub
If IsNull(Me.子窗体控件的名称.ljid) Then
MsgBox "请输入零件名称", vbCritical, "提示"
Me.子窗体控件的名称.ljid.SetFocus
Exit Sub
End If
If IsNull(Me.子窗体控件的名称.sl) Then
MsgBox "请输入零件数量", vbCritical, "提示"
Me.子窗体控件的名称.sl.SetFocus
Exit Sub
End If
关于什么是子窗体控件名称,见视频讲解:
http://www.accessoft.com/bbs/showtopic.asp?ID=575&BoardID=24
总记录:1篇 页次:1/1 9 1 :