1、创建或者引用access数据库首先你自己得有个数据库,这个就不多说了,网上好像挺多的,自己建一个或者用别人的xx.accdb文件(我就是用的别人的)。
2、添加一个按钮创建->空白窗体,在图形界面中,拖一个按钮到界面上去(那个按钮还有好多种,我选的是杂项,再取消)。然后选择视图->设计视图,然后右键那个按钮,选属性,右边就会出现一个属性表。找到单击,点击后面的省略号按钮,选择代码生成器,就进入编程界面了
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