access 按钮 多条sql语句 VBA

 时间:2024-10-13 12:42:40

1、创建或者引用access数据库首先你自己得有个数据库,这个就不多说了,网上好像挺多的,自己建一个或者用别人的xx.accdb文件(我就是用的别人的)。

2、添加一个按钮创建->空白窗体,在图形界面中,拖一个按钮到界面上去(那个按钮还有好多种,我选的是杂项,再取消)。然后选择视图->设计视图,然后右键那个按钮,选属性,右边就会出现一个属性表。找到单击,点击后面的省略号按钮,选择代码生成器,就进入编程界面了

access 按钮 多条sql语句 VBA

3、然后你就可以写你要执行的一系列代码了,我的比较简单,有比较复杂的请自行百度Pr坡纠课柩ivate Sub Command0_潮贾篡绐Click()str1 = "create table result(NewID char(255),DoAdmit Date,DoDischarge Date,Interval long)"str2 = "insert into result(NewID,DoAdmit)select distinct NewID,(select max(DoAdmit) from 2002table b where b.NewID = a.NewID) as DoAdmit from ( select NewID from 2002table group by NewID having count(NewID)>1) a"str3 = "select NewID,(select max(DoDischarge) from 2002table a where a.NewID = r.NewID And a.DoAdmit = r.DoAdmit) as DoDischarge into t from result r"str4 = "select b.NewID, (select top 1 DoDischarge from 2002table a where a.NewID = b.NewID And a.DoDischarge <> b.DoDischarge order by DoDischarge desc) as DoDischarge into t1 from t b "str5 = "UPDATE result a,t1 b Set a.DoDischarge = b.DoDischarge WHERE a.NewID = b.NewID"str6 = "update result set interval=doadmit-dodischarge"str7 = "drop table t"str8 = "drop table t1"CurrentDb.Execute (str1)CurrentDb.Execute (str2)CurrentDb.Execute (str3)CurrentDb.Execute (str4)CurrentDb.Execute (str5)CurrentDb.Execute (str6)CurrentDb.Execute (str7)CurrentDb.Execute (str8)End Sub

access 按钮 多条sql语句 VBA
  • access如何将窗体里的子窗体作为打印内容
  • 教程:在Excel 2013中导入Access数据的方法
  • Access中如何只使需要的字段出现?
  • 如何在组合框中显示文件列表
  • access怎样对特定的地址发出警告
  • 热门搜索
    伊索寓言手抄报 讲卫生手抄报内容 七彩童年手抄报图片 数学手抄报图片大全 遵纪守法手抄报图片 精美手抄报图片 传统文化手抄报模板 足球手抄报 我爱科学手抄报内容 勾股定理手抄报