当前位置:首页 > 实用Access代码程序
Select Case Weekday(Date, vbMonday) Case 1
Me![txtWeek] = \星期一\ Case 2
Me![txtWeek] = \星期二\ Case 3
Me![txtWeek] = \星期三\ Case 4
Me![txtWeek] = \星期四\ Case 5
Me![txtWeek] = \星期五\ Case 6
With txtWeek
.ForeColor = 255 End With
Me![txtWeek] = \星期六\ Case 7
With txtWeek
.ForeColor = 255 End With
Me![txtWeek] = \星期日\ End Select
Me.txtTime.Value = now() End Sub
‘关闭所有窗体
dim intx as integer dim intCount as integer intCount = Forms.count-1
for intX= intCount to 0 step -1 docmd.close acform,forms(intX).name next
‘*************OR************** for intX= intCount to 0 step -1
if forms(intX).Name <> \ docmd.close acform,forms(intX).name end if next
返回年龄
Public Function srAge(Birthday As Date, NowDate As Date) As Integer '返回年龄
srAge = Int((NowDate - Birthday) / 365.25)
End Function
'************* Code End **************
不用查询在一个表内自加减的办法1:
1.新建一个人费用表“个人费用”
id 年月 工资 日期 支出 剩余 数字 文本 数字 日期 数字 长整型 单精度型 单精度型 单精度型 2.新建一窗体:Form-个人费用(数据表视图)
记录源:SELECT 个人费用.id, 个人费用.年月, 个人费用.工资, 个人费用.支出, 个人费用.剩余, 个人费用.日期, 个人费用.备注 FROM 个人费用 ORDER BY 个人费用.id;
代码:
Option Compare Database
------------------------------------------------------------
Private Sub Form_BeforeInsert(Cancel As Integer) 插入前 Me.id = DMax(\个人费用\If Me.Recordset.RecordCount = 0 Then Me.id = 1 End If End Sub
------------------------------------------------------
Private Sub 工资_AfterUpdate() 更新后 Dim counter
If Me.Recordset.RecordCount < 1 Then Me![剩余] = Nz(Me![工资]) - Me.支出 Else
DoCmd.GoToRecord , , acPrevious counter = Me![剩余]
DoCmd.GoToRecord , , acNext
Me![剩余] = Nz(Me![工资]) + counter - Me.支出 End If End Sub
-----------------------------------------------------------------
Private Sub 支出_AfterUpdate() 更新后 Dim counter
If Me.Recordset.RecordCount < 1 Then Me![剩余] = Nz(Me![工资]) - Me.支出 Else
DoCmd.GoToRecord , , acPrevious counter = Me![剩余]
DoCmd.GoToRecord , , acNext
Me![剩余] = Nz(Me![工资]) + counter - Me.支出 End If End Sub
在窗体的文本框中变化数字:(Interval=100)
Private Sub Form_Timer() i = i + 10
text20.SetFocus
text.20.Text = Str(i / 10)
If i = 700 Then DoCmd.Close End Sub
不用查询在一个表内自加减的办法2:
1.新建一个银行存款表“银行存款”
识别码 日期 存入 提款 自动编号 日期/时间 货币 货币 主键 2.新建一个查询“查询名“(来源为表:银行存款)
字段: 表: 排序: 显示: 日期 银行存款 货币 存入 银行存款 提款 银行存款 余额: f([日期]) 3.新建一个模块“模块1“代码如下:
Option Compare Database
------------------------------------------------------------------------------- Public Function f(d As Date) As Currency Dim a As Currency Dim b As Currency
a = Nz(DSum(\银行存款]![存入]\银行存款]\日期] <= # \ b = Nz(DSum(\银行存款]![提款]\银行存款]\日期] <= # \
f = a - b
End Function
此查询不能直接用于窗体,新加项后余额显示错误,要想用于窗体必需从窗体中再编程
制做弹出菜单:
Private Sub Image0_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
With Me.Image0 .Height = 400 End With
Me.cmdAddUser.Visible = True Me.cmdClose.Visible = True Me.cmdPowerSet.Visible = True End Sub
---------------------------------------------------------- Private Sub Form_Load() With Me.Image0
共分享92篇相关文档