473,378 Members | 1,394 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 software developers and data experts.

Exporting Excel cells to Access using VBA

The code below works but I don’t understand the Values (line line 9). I keep getting error messages. Could someone add more fields to it, such as:
F24 into Ingredient2
F25 into Ingredient3
F26 into Ingredient4
G24 into Lot2
G25 into Lot3
G26 into Lot4
The Ingredient column and the Lot column will both have 30 rows for data.

Expand|Select|Wrap|Line Numbers
  1. Sub Button10_Click()
  2. Dim strSQL As String
  3.  
  4. Set appAccess = CreateObject("Access.Application")
  5.  
  6. appAccess.Visible = False
  7.  
  8. strSQL = "INSERT INTO [Finished Batches] ([Production Date],[Lot_Number],[Ingredient1],[Amount1]) " & _
  9.          "VALUES (#" & Range("C5") & "#,'" & Range("D5") & "','" & Range("F23") & _
  10.          "'," & Range("G23") & ")"
  11.  
  12. With appAccess
  13.   .OpenCurrentDatabase ("C:\users\jay neuh\desktop\database\ss database.mdb")
  14.   .DoCmd.RunSQL strSQL, dbFailOnError
  15.   .CloseCurrentDatabase
  16. End With
  17.  
  18. Set appAccess = Nothing
  19. End Sub
  20.  
Jan 28 '15 #1
8 1448
twinnyfo
3,653 Expert Mod 2GB
If you already have the Access Project, it might be easier to import into Access from Access. Access allows you to link Spreadsheets and treat them as tables. This greatly speeds up the import process.
Jan 28 '15 #2
I wish I could attach my spreadsheet, I don't think it will work as a table. It contains a bunch of calculations.
Jan 28 '15 #3
Here is the spreadsheet I'm using.

https://mega.co.nz/#!2cZ3kKAZ!BL-HJM...1tZewrw-CH-1Dc
Jan 29 '15 #4
twinnyfo
3,653 Expert Mod 2GB
I cannot open the link.

Do you need the calculations or only the values represented by the calculations?
Feb 2 '15 #5
I need the values. I hope this link will work, I think it would really help it you saw me excel sheet. Maybe this would be easier if I copied ( =sheet1!a1 ) all the values to sheet2 in one long row with a header row.
https://mega.co.nz/#!2cZ3kKAZ!BL-HJM...1tZewrw-CH-1Dc
Feb 2 '15 #6
twinnyfo
3,653 Expert Mod 2GB
If you only need the values, then you can still link the Spreadsheet, as only the value is displayed, not the calculation or formula.
Feb 2 '15 #7
Thanks twinnyfo, Im willing to try it. I want the user to be able to use the info on the spreadsheet and enter more data onto it, then export into access. Each time the sheet is used it will have a new name. I would still like to see what Lines 8,9 and 10 would look like if the select and insert were changed to:

F24 into Ingredient2
F25 into Ingredient3
F26 into Ingredient4
G24 into Lot2 (Formated as number
G25 into Lot3 (Formated as number
G26 into Lot4 (Formated as number
Feb 2 '15 #8
twinnyfo
3,653 Expert Mod 2GB
If you simply want to expand the code you have above, all your "Insert Into" values are on the same line and all your "Values" are on another line. Gradually expand your code to make sure it works with each addition and you should be able to work it through.

We can help with trouble shooting.

It looks like your spreadsheet is less of a "table" and just holds somewhat random, but standardized information.
Feb 2 '15 #9

Sign in to post your reply or Sign up for a free account.

Similar topics

5
by: jsudo | last post by:
I have a Access database with a large amount of records (close to 500,000) that I would like to export to Excel. I found out that Excel has the capability of of about 65,000 rows so I know I...
0
by: Jack | last post by:
Windows 2K Pro Access/Excel 2003 Hi there, I have a large number of password protected Excel Workbooks. The files are protected by code that runs when the workbook opens. The code asks the...
2
by: T2 | last post by:
I need some code ideas to import Excel into Access using VB. I need to use VB because the Excel column formats are not always consistent. I'm importing a fairly simple spreadsheet. Any...
0
by: genojoe | last post by:
I have a 4 column, 6 row Excel sheet with all cells formatted for text: 1 1 a a 2 2 b b 3 3 c c a 4 d 1 b 5 e 2 c 6 f 3 I have the following schema.ini:
3
by: ofilha | last post by:
I need to format a column in excel but would like to do it from Access using VB. I have hacked around and found a few ways to get to the workbook but have a problem getting to the sheet i want. But,...
2
by: muddasirmunir | last post by:
I want to know how can we Import data from Excel into Excel Using vb6. Any help where can i start ?
0
by: jason1286 | last post by:
I currently have code that exports from Excel to Access to add to the bottom of the table. However, if my data in Excel has a primary key that already exists in the Access table it causes an error...
2
by: mdtam | last post by:
Hi experts, I would like to import data from excel into access. For example I have field "Name" in the excel table. Then I want to import all the data under the field into my database (ms access).
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.