Access交流中心

北京 | 上海 | 天津 | 重庆 | 广州 | 深圳 | 珠海 | 汕头 | 佛山 | 中山 | 东莞 | 南京 | 苏州 | 无锡 | 常州 | 南通 | 扬州 | 徐州 | 杭州 | 温州 | 宁波 | 台州 | 福州 | 厦门 | 泉州 | 龙岩 | 合肥 | 芜湖 | 成都 | 遂宁 | 长沙 | 株洲 | 湘潭 | 武汉 | 南昌 | 济南 | 青岛 | 烟台 | 潍坊 | 淄博 | 济宁 | 太原 | 郑州 | 石家庄 | 保定 | 唐山 | 西安 | 大连 | 沈阳 | 长春 | 昆明 | 兰州 | 哈尔滨 | 佳木斯 | 南宁 | 桂林 | 海口 | 贵阳 | 西宁 | 乌鲁木齐 | 包头 |

老师帮我看看,这段程序有问题吗?这是教材上的程序,引用ADO后仍应然通不过,问题出在哪里?

武士气  发表于:2017-12-01 09:46:16  
复制

Private Sub save_Click()
Dim db As Datadase
Set db = CurrentDb()
If Nz([code]) = "" Then
  MsgBox ("请选择商品编制码!")
Else
  DoCmd.RunSQL ("insert into buy([datetime],code,amount,price)select [datetime],[code],[amount],[price]")
  If db.OpenRecordset("select * from stock where code='" & [code] & "'").RecordCount = 0 Then
     DoCmd.RunSQL ("insert into stock(code,amount,[money])select [code],[amount],[money]")
  Else
     DoCmd.RunSQL ("update stock set stock.amount=stock.amount+" & [amount] & ",stock.money=stock.money+" & [money] & " where code='" & [code] & "'")
  End If
End If
Me.datatime.Value = Now()
Me.code.Value = Null
Me.amount.Value = Null
Me.price.Value = Null
End Sub
这段程序的作用是将窗体文本框的内容保存到对应的表中。

 

Top
西出阳关无故人 发表于:2017-12-01 16:39:31

先说这一句

DoCmd.RunSQL ("insert into buy([datetime],code,amount,price)select [datetime],[code],[amount],[price]")

1、select 之前没有空格;

2、用到select就要有from,缺失from及后面的表或查询名称

例如:DoCmd.RunSQL ("insert into buy([datetime],code,amount,price) select [datetime],[code],[amount],[price] from 表名称")

如果select 后面的[datetime],[code],[amount],[price]是窗体控件名称,就用以下形式(日期时间用#,文本用‘,数字不需要):

DoCmd.RunSQL  "insert into buy([datetime],code,amount,price) values (#"&datetime & "#,'" & [code] & "','" & [amount] & "','" & [price] & "')"



武士气 发表于:2017-12-04 11:13:44

这是四川省的张巍老师编制写的《数据库应用基础——access2010》上的程序实例,用于将窗体文本框中的数值保存到相应表中,原文照抄,去试则通不过,非常感谢老师不吝指教




西出阳关无故人 发表于:2017-12-04 14:09:55
问题解决没有?

武士气 发表于:2017-12-26 10:56:15
解决了,谢谢老师

总记录:4篇  页次:1/1 9 1 :