简体   繁体   English

带有 vba 代码和导入的表单

[英]Forms with vba code and importing

How to create an access form which has two fields for importing two different excel files, and after selecting excel files press the button to run a query (already exist) and automatically export the query result in excel sheet.如何创建一个包含两个字段的访问表单,用于导入两个不同的excel文件,并在选择excel文件后按按钮运行查询(已存在)并自动将查询结果导出到excel表中。 I was able to create the vba code (once played the import dialog will pop up waiting the user to enter the file path then pops up another time for the second file, another dialoge for exporting the result to excel. but the problem is how to do it using Forms in Microsoft Access.please give me suggestions or reference.我能够创建 vba 代码(一旦播放,将弹出导入对话框,等待用户输入文件路径,然后再次弹出第二个文件,另一个用于将结果导出到 excel 的对话框。但问题是如何使用 Microsoft Access 中的表单进行操作。请给我建议或参考。

Agree with Boeckm, your question is a little lacking in detail :-)同意 Boeckm,你的问题有点缺乏细节:-)

If you are asking for the VBA code to fire the macro's you already have then simply create a button and add the following to the [on click] property如果您要求 VBA 代码触发您已有的宏,则只需创建一个按钮并将以下内容添加到 [on click] 属性中

Private Sub Excel_button_Click(Cancel As Integer)

    DoCmd.SetWarnings False    ' Switch off "Are you sure" message

    Dim stDocName As String
    stDocName = "qry_Import file 1"
    DoCmd.OpenQuery stDocName, acNormal, acEdit

    stDocName = "qry_Import file 2"
    DoCmd.OpenQuery stDocName, acNormal, acEdit

    stDocName = "qry_Export file 3"
    DoCmd.OpenQuery stDocName, acNormal, acEdit   

    DoCmd.SetWarnings True    ' Switch on "Are you sure" message

End Sub

You can also build this in a single button using the wizzard (select misc, run query and select the first import query. Go back to the button and edit the [embedded macro] adding the others. You can also add the set warning = off to the series if required).您还可以使用向导在单个按钮中构建它(选择 misc,运行查询并选择第一个导入查询。返回按钮并编辑 [embedded macro] 添加其他人。您还可以添加 set warning = off如果需要,到系列)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM