access如何在打开窗体时自动新建一个记录?

access如何在打开窗体时自动新建一个记录?,第1张

选中要 *** 作窗体,右键选“设计视图”,在打开的设计视图【窗体】属性中点击上方的“事件”选项卡,选中【加载】,然后点击后面的?按钮,d出窗口中选择【宏生成器】或者【代码生成器】,然后对照下面 *** 作:\r\n方法一、【宏生成器】法:\r\n1、d出的对话框中先给宏指定一个名称,比如:添加新记录\r\n2、在【添加新记录: 宏】窗口的“ *** 作”处选择:GoToRecord\r\n然后在下面的“ *** 作参数”处进行如下设置:\r\n1)对象类型:窗体\r\n2)对象名称:选你要 *** 作的窗体\r\n3)记录:选“新记录”\r\n4)保存退出。\r\n方法二、【代码生成器】法:\r\n在d出的VB编辑器中鼠标光标激活处添加如下代码:\r\nDoCmd.GoToRecord , , acNewRec\r\n然后关闭VB编辑器。\r\n最后:无论采取那个方法,关闭窗体的“设计视图”时选“保存”即可!

“修改”按钮的程序 \x0d\x0aPrivate Sub cmdEdit_Click() \x0d\x0asql = "select * from 停时统计 where date = cdate('" &Text8.Text &"') and ycqk = '" &Combo1.Text &"'and id = '" &DataGrid1.Columns(2).CellText(DataGrid1.Bookmark) &"'" \x0d\x0ars.Open sql, dm, adOpenDynamic, adLockOptimistic \x0d\x0ars.Fields("id") = Text7.Text \x0d\x0ars.Fields("ycqk") = Combo1.Text \x0d\x0ars.Fields("date1") = Text1.Text \x0d\x0ars.Fields("time1") = Text2.Text \x0d\x0ars.Fields("date2") = Text3.Text \x0d\x0ars.Fields("time2") = Text4.Text \x0d\x0ars.Update \x0d\x0ars.Close \x0d\x0aEnd Sub \x0d\x0a\x0d\x0a'“删除”按钮的程序 \x0d\x0aPrivate Sub cmdDelete_Click() \x0d\x0astrFCode = DataGrid1.Columns(0).CellText(DataGrid1.Bookmark) \x0d\x0astrSCode = DataGrid1.Columns(2).CellText(DataGrid1.Bookmark) \x0d\x0astrCCode = DataGrid1.Columns(1).CellText(DataGrid1.Bookmark) \x0d\x0asql = "select * from 停时统计 where date='" &strFCode &"' and id='" &strSCode &"' and ycqk='" &strCCode &"'" \x0d\x0ars.Open sql, dm, adOpenDynamic, adLockOptimistic \x0d\x0ars.Delete \x0d\x0ars.Update \x0d\x0ars.Close \x0d\x0aEnd Sub \x0d\x0a\x0d\x0a'“增加”按钮的程序 \x0d\x0aPrivate Sub Command1_Click() \x0d\x0asql = "select * from 停时统计 order by id" \x0d\x0ars.Open sql, dm, adOpenDynamic, adLockOptimistic \x0d\x0ars.AddNew \x0d\x0ars.Fields("date") = Date \x0d\x0ars.Fields("id") = Text7.Text - 1 \x0d\x0ars.Fields("ycqk") = Combo1.Text \x0d\x0ars.Fields("date1") = Text1.Text \x0d\x0ars.Fields("time1") = Text2.Text \x0d\x0ars.Fields("date2") = Text3.Text \x0d\x0ars.Fields("time2") = Text4.Text \x0d\x0ars.Update \x0d\x0ars.Close \x0d\x0a\x0d\x0aWith Adodc1 \x0d\x0aAdodc1.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0Data Source=" &App.Path &"\db1.mdbPersist Security Info=False" \x0d\x0aAdodc1.RecordSource = "select * from 停时统计 where date = cdate('" &Text8.Text &"') and ycqk = '" &Combo1.Text &"' order by id" \x0d\x0aAdodc1.Refresh \x0d\x0aDataGrid1.Refresh \x0d\x0aEnd With \x0d\x0aEnd Sub


欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/bake/11958965.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-05-20
下一篇 2023-05-20

发表评论

登录后才能评论

评论列表(0条)

保存