复制选定的值和文本框的值和附加表 - MS访问VBA [英] Copy Selected Value and TextBox Value and Append to Table - MS Access VBA

查看:277
本文介绍了复制选定的值和文本框的值和附加表 - MS访问VBA的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在做实习在夏天已经结束了做一个访问数据库的一些工作。我一直在寻找一种方式来使用VBA code追加,用户已经从一个子窗体(图中所示)的查询选择一个位置号码和一个数字,他们进入了一个文本框上的previous形式,向现有的表。该表已为自动编号主键。

I'm doing an internship over the summer and have ended up doing some work on an access database. I have been searching for a way to use VBA code to append a location number which the user has selected from a query in a subform (shown in the picture) and a number which they entered into a text box on a previous form, to an existing table. This table has autonumber as the primary key.

要当用户点击选择网站我想获得从另一种形式的文本框复制code和任何地点,他们选择了复制汇总/高亮(在这种情况下,9.01),并使用双其中,形成在现有表中的新纪录。我只需要复制的9.01 - 不是整个记录

To summarise when the user clicks "Select Site" I would like access to copy a code from a text box on another form and copy whichever location they have selected/highlighted (in this case 9.01) and use the two of them to form a new record in an existing table. I only need to copy the 9.01 - not the whole record.

任何帮助将是非常美联社preciated!

Any help would be much appreciated!

推荐答案

您可以用code这样来完成你想做的事情。插入此code在您的按钮的Click事件,改变形式,表,列和参数名称为您所需要的:

You can use code like this to accomplish what you want to do. insert this code to the Click event on your button and change the form, table, column, and parameter names to what you need:

On Error GoTo ErrorHandler

    Dim db As DAO.Database
    Dim qdf As DAO.QueryDef

    Set db = CurrentDb()

    Set qdf = db.CreateQueryDef("", "INSERT INTO [MyTable] (MyCol1, MyCol2) VALUES ([MyVal1], [MyVal2])")
    qdf.Parameters("[MyVal1]") = Forms![MyForm1]![MyControl1]
    qdf.Parameters("[MyVal2]") = Forms![MyForm2]![MyControl2]

    qdf.ReturnsRecords = False
    qdf.Execute

ExitMe:
    Set qdf = Nothing
    Set db = Nothing

    Exit Sub
ErrorHandler:
    MsgBox Err.Number & ": " & Err.Description
    GoTo ExitMe

这篇关于复制选定的值和文本框的值和附加表 - MS访问VBA的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆