简体   繁体   English

如何从Access将单个记录导出到Excel中的特定单元格

[英]How do I export a single record from Access to specific cells in Excel

I am trying to export the record displayed on a form in Access to an Excel template which I would then rename and use the data in further calculations. 我试图导出在Excel模板的Access中的表单上显示的记录,然后我将其重命名并在进一步的计算中使用数据。 I want to click a button on the form to transfer the record to Excel, I rename it and be done. 我想单击表单上的按钮以将记录传输到Excel,我将其重命名并完成。 The data fields will need to go to specific cells in the spreadsheet. 数据字段将需要转到电子表格中的特定单元格。 Each record represents a seasoning formula with fields as such: Formula_name Formula_number Date_entered Ingredient1 Amount1 Ingredient2 Amount2 Ingredient3 And so on 每个记录代表一个调味配方,其字段如下:Formula_name Formula_number Date_entered Ingredient1 Amount1 Ingredient2 Amount2 Ingredient3等

The amounts are a percent of total amount. 金额是总额的百分比。 Ingredients and amounts need to be in columns. 成分和数量必须在列中。 I will send the newly named excel sheet (Batch Sheet) to a pc in production for pulling, weighing and lot code recording. 我会将新命名的excel表格(批处理表格)发送到生产中的PC,以进行提取,称重和批号记录。 I have looked at vba but don't have time to learn it in time for this project so I am hoping to just cut and paste the code or better-yet email the database and excel template to someone much smarter than me and have it working when returned. 我看过vba,但没有时间及时学习该项目,因此我希望剪切并粘贴代码,或者更好地将数据库和excel模板通过电子邮件发送给比我聪明得多的人并使其正常工作返回时。 $$ Also can it work with different versions of MS Office. $$它还可以与不同版本的MS Office一起使用。 Thanks. 谢谢。

This is not exactly a trivial 'cut and paste' problem unless you really want a simple solution without any customization. 除非您真的想要一个没有任何自定义的简单解决方案,否则这并不是一个简单的“剪切和粘贴”问题。

Here is a link to an article that shows how to do it: http://www.accessibledatasolutions.com/articles11/AccessToExcel.htm 这是显示该操作方法的文章的链接: http : //www.accessibledatasolutions.com/articles11/AccessToExcel.htm

In general you need to use something like the following code. 通常,您需要使用类似以下代码的内容。 You need to adjust the paths and then the SQL statement and you can put the extracted values from Access wherever you want. 您需要先调整路径,然后再调整SQL语句,然后可以将Access中提取的值放在所需的任何位置。 Maybe you can start with this and get some easy SQL extraction running. 也许您可以从此开始并获得一些简单的SQL提取运行。

Sub ConnectDatabase()

Dim con As New ADODB.Connection
Dim connected As Boolean
Dim rstAnswer As New ADODB.Recordset
Dim RootPath, DBPath As String
Dim tempString As String

connected = False

RootPath = "C:\Test\"
DBPath = RootPath & "Test.accdb"
con.Open "Provider=Microsoft.ACE.OLEDB.12.0; Data Source=" & DBPath & ";"

connected = True

rstAnswer.Open "SELECT CustomerName From tblCustomers " & _
    "WHERE tblCustomers.Country = '" & Denmark & "';", con, adOpenKeyset, adLockOptimistic

Do Until rstAnswer.EOF
    tempString = CStr(rstAnswer!CustomerName)
    Application.ActiveWorkbook.Worksheets("Sheet1").Range("A1").Value = tempString
    rstAnswer.MoveNext
Loop

rstAnswer.Close
con.Close   
connected = False

End Sub

暂无
暂无

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

相关问题 如何从Access将2个查询导出到excel中的单个工作表 - How do I export 2 queries to a single worksheet in excel from access 如何写入Excel中的特定单元格? - How do I write to specific cells in Excel? 如何将Excel单元格导出到特定的HTML标签? - How can I export Excel cells to specific HTML tags? 如何在不引用其他单元格的情况下将报表从Reporting Services 2005导出到Excel? - How do I export reports from Reporting Services 2005 to Excel without the references to other cells? 如何在Excel中将记录/单元格链接到图表? FullSeriesCollection - How do I link a record/cells to a chart in Excel? FullSeriesCollection 如何将范围从Excel导出到特定的ms Access 2010字段 - how to export a range from excel to a specific ms access 2010 field 如何将EXCEL 2010中的选定单元格导出为HTML。 每次导出的像元范围可能不同吗? - How do I export selected cells in EXCEL 2010 as HTML. Cell range may be different on each export? 如何编写 R 代码以通过特定单元格直接从 excel 读取? - How do I write R code to read directly from excel by specific cells? 如何在Excel中按特定字符将字符串分成多个单元格? - How do I separate a String into multiple cells by specific character in excel? 如何使用 Excel VBA 从两个工作簿中复制特定单元格并将它们合并为一个? - How do I use Excel VBA to copy specific cells from two workbooks and combine them into one?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM