473,325 Members | 2,870 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,325 software developers and data experts.

Importing CERTAIN fields from Excel into Access?

Dpot
30
I created a template in excel that matches the layout of a form I have in my Access Database. The reason for this is we can export all the data of one record into the template, email it to someone, that someone can fill in whatever portions they need to fill in and send it back.

This is where I'm running into trouble, the next thing we need to be able to do is take what has been emailed back to us and import the excel fields that have been filled in (they are pre-defined) into our Access form. I have found plenty of codes for importing data, but they make you import the entire excel file. Could someone help point me in the direction of a code that lets you set pre-defined fields in it to import from Excel?
Jan 13 '15 #1
2 1307
jimatqsi
1,271 Expert 1GB
Dpot,
All you need to do is to link to the excel file and write a query using that new table name (the table name that points to the linked excel file). In your query you can use whichever fields you choose.

There are other ways, including a predefined import process that skips certain fields, but I think the linked table is the simplest.

Jim
Jan 14 '15 #2
jforbes
1,107 Expert 1GB
Jim has got your answer for using as spreadsheet as a datasource.

The following is a quick and dirty way to get the value of a Range in a Spreadsheet. This uses early binding, so you'll need a reference to a Microsoft Excel x.x Object Library. If you start running into versioning problems, the code may need to be converted to late binding and then the reference wouldn't be needed. Lastly, I haven't worried about putting in error handling and a validator to check to see if the file exists.
Expand|Select|Wrap|Line Numbers
  1. Public Function getExcelValue(ByRef sSpreadsheet As String, sRange As String) As String
  2.  
  3.     Dim oExcel As Excel.Application
  4.     Dim oWorkbook As Excel.Workbook
  5.     Dim oSheets As Excel.Sheets
  6.     Dim oSheet As Excel.Worksheet
  7.  
  8.     Set oExcel = New Excel.Application
  9.     Set oWorkbook = oExcel.Workbooks.Open(sSpreadsheet, ReadOnly:=True)
  10.     Set oSheets = oWorkbook.Sheets
  11.     Set oSheet = oWorkbook.Sheets(1)
  12.     getExcelValue = oSheet.Range(sRange)
  13.  
  14.     If Not oWorkbook Is Nothing Then
  15.         oWorkbook.Close SaveChanges:=False
  16.         Set oWorkbook = Nothing
  17.     End If
  18.     If Not oExcel Is Nothing Then
  19.         oExcel.Quit
  20.         Set oExcel = Nothing
  21.     End If
  22.  
  23. End Function
The variable oSheet cracks me up.
Jan 14 '15 #3

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

Similar topics

1
by: Chumley the Walrus | last post by:
Is there anyway inside a datagrid's parameter list to disallow certain fields in the dataset to be viewed ?
2
by: sarhjinian | last post by:
I'm having some trouble working with an ODBC query of a large SQL Server table in Access. The table is ~440 fields in size (I know, but its not my database). I only need about six of these fields...
3
by: alex_peri | last post by:
Hello All, I am having problems with sorting a recordset by fields in Access. I have a table with three columns called ID, SNo and Time and would like to sort the records by Time. I would like to...
2
by: llucas | last post by:
After saving a record using a form, I want certain fields on the data entry form to display the same information from the previous record.
2
by: ScardyBob | last post by:
Hello, I am having trouble importing data from an Excel Worksheet. When I try to import the data, everything works except certain columns that contain dates, where it replaces the date with a...
2
by: steph | last post by:
I have a table with 250 fields. Of course you are wondering why 250 fields... what could I possibly be storing in so many fields? I am using this table as a general import table for files that...
24
by: MNNovice | last post by:
tblExpDetails has various fields including two Yes/No fields and one Category field. frmExpDetails is based on this table. I would like to add some restrictions wWhen an end user is using...
2
by: Medaron | last post by:
I am trying to wite a vba code to read all my outlook task fields in Access database. So far I have following code: Sub OutlookTasks() Dim ol As Object Dim olns As Object Dim objFolder As...
11
by: sam71999 | last post by:
I have table Name score A 20 B 40 c 10 d 70 I want create Form Name Score Total A 20 20
7
by: Amian | last post by:
Hello, I'm struggling with figuring out how to have my form auto select certain fields in access 2010. I only want fields to show up on a form if certain data was entered in a field in a diff...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
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...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you

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.