设为首页收藏本站Access中国

Office中国论坛/Access中国论坛

 找回密码
 注册

QQ登录

只需一步,快速开始

返回列表 发新帖
查看: 3084|回复: 6
打印 上一主题 下一主题

[宏/菜单/工具栏] 如何使用宏添加记录

[复制链接]
跳转到指定楼层
1#
发表于 2012-6-24 16:46:39 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
,在窗体上如何使用宏来添加记录?哪位大侠能帮忙解决下!

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有帐号?注册

x
分享到:  QQ好友和群QQ好友和群 QQ空间QQ空间 腾讯微博腾讯微博 腾讯朋友腾讯朋友
收藏收藏 分享分享 分享淘帖 订阅订阅
2#
发表于 2012-6-24 18:56:35 | 只看该作者
绑定表,直接输入就是了!
3#
 楼主| 发表于 2012-6-25 15:03:28 | 只看该作者
{:soso_e101:},不想这么干
4#
发表于 2012-6-25 15:57:02 | 只看该作者
wuchju 发表于 2012-6-25 15:03
,不想这么干

那你想将记录保存到那个表中
5#
发表于 2012-6-26 10:07:18 | 只看该作者
  1. Private Sub Command10_Click()
  2.     Dim ctl As Control
  3.     Dim rs As New ADODB.Recordset
  4.     For Each ctl In Me.Controls
  5.         If TypeOf ctl Is TextBox Or TypeOf ctl Is ComboBox Then
  6.             If IsNull(ctl) Then
  7.                 MsgBox ctl.Name & " 不可为空! "
  8.                 ctl.SetFocus
  9.                 Exit Sub
  10.             End If
  11.         End If
  12.     Next
  13.     With rs
  14.         .Open "消费记录", CurrentProject.Connection, adOpenKeyset, adLockOptimistic
  15.         .AddNew
  16.         .Fields("id") = Me.ID
  17.         .Fields("日期") = Me.日期
  18.         .Fields("二级类目id") = Me.二级类目ID
  19.         .Fields("金额") = Me.金额
  20.         .Fields("说明") = Me.说明
  21.         .Update
  22.         .Close
  23.     End With
  24.     MsgBox "记录已保存!"
  25.     Set rs = Nothing
  26. End Sub
复制代码
6#
发表于 2012-6-26 10:07:49 | 只看该作者
  1. Private Sub Command10_Click()
  2.     Dim ctl As Control
  3.     Dim rs As New ADODB.Recordset
  4.     For Each ctl In Me.Controls
  5.         If TypeOf ctl Is TextBox Or TypeOf ctl Is ComboBox Then
  6.             If IsNull(ctl) Then
  7.                 MsgBox ctl.Name & " 不可为空! "
  8.                 ctl.SetFocus
  9.                 Exit Sub
  10.             End If
  11.         End If
  12.     Next
  13.     With rs
  14.         .Open "消费记录", CurrentProject.Connection, adOpenKeyset, adLockOptimistic
  15.         .AddNew
  16.         .Fields("id") = Me.ID
  17.         .Fields("日期") = Me.日期
  18.         .Fields("二级类目id") = Me.二级类目ID
  19.         .Fields("金额") = Me.金额
  20.         .Fields("说明") = Me.说明
  21.         .Update
  22.         .Close
  23.     End With
  24.     MsgBox "记录已保存!"
  25.     Set rs = Nothing
  26. End Sub
复制代码
7#
 楼主| 发表于 2012-9-12 11:53:36 | 只看该作者
谢谢!这是用上VBA了。
您需要登录后才可以回帖 登录 | 注册

本版积分规则

QQ|站长邮箱|小黑屋|手机版|Office中国/Access中国 ( 粤ICP备10043721号-1 )  

GMT+8, 2024-5-3 20:21 , Processed in 0.128829 second(s), 31 queries .

Powered by Discuz! X3.3

© 2001-2017 Comsenz Inc.

快速回复 返回顶部 返回列表