473,378 Members | 1,500 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.

How to add data to just one field in Access?

Hi, I have a function to import records from excel into Access. I want to add a particular cell value in Excel under a particular field in the access table and do this until I reach the end of file. The cell value will be a date like: 09/20/2010. The field name in Access is "Date". Since the date appears in the 3rd row, 3rd column in Excel I tried something like this but didn't work:

Dim newVar As Variant
Set newVar = wks.Cells(3, 3)
![CCTVPipeTemporary].Date = newVar

Thanks.
Jan 25 '11 #1
2 1554
jimatqsi
1,271 Expert 1GB
I would simply link to the Excel sheet and write a query to do that. Use File/ImportData/Link and specify Excel sheet as the type.

The Excel sheet ends up looking like a table in the database so to write an append or update query is all you need to do.
Jan 26 '11 #2
I actually fixed that problem, but now I have run into another problem with a For loop. When filling up the Access table from excel I want to skip two columns and not add their data. Namely, columns 28 and 29 in Excel which correspond to Fields 26 and 27 in my access table. so I have a variable iFld which keeps track of the fields and iRow and iCol which keep track of the rows and columns in the excelsheet. I have the following For Loop which fills up the table. I am trying to skip those columns (28 and 29) in the for loop. I have failed to do this successfully. I tried an if Then statement in the For loop and although it skipped the rows I did not get any data imported into the table. Here it is:

Expand|Select|Wrap|Line Numbers
  1. Public Function ProcessFileImport(sFile As String, sTable As String, cStartRow1 As Byte, cStartColumn1 As Byte, cStartField1 As Byte, cTab1 As Integer) As String
  2.  
  3. Set ExcelBook = ExcelApp.Workbooks.Open(sFile)
  4. Set wks = ExcelApp.Worksheets(cTab1)
  5.  
  6.     Set dbs = CurrentDb
  7.    sSQL = "SELECT * FROM " & sTable
  8.    Set rst = dbs.OpenRecordset(sSQL)
  9.  
  10.    With rst
  11.    .AddNew
  12.    End With
  13.  
  14.    iCol = cStartColumn1
  15.    iRow = cStartRow1
  16.  
  17.    Do While Not wks.Cells(iRow, 1) = ""
  18.  
  19.    cStartField1 = rst.Fields(0)
  20.  
  21.   iFld = cStartField1
  22.       lRecords = lRecords + 1
  23.  
  24.  
  25.       For iCol = cStartColumn1 To cStartColumn1 + (rst.Fields.Count - (cStartField1 + 1))
  26.  
  27.  
  28.          rst.Fields(iFld) = wks.Cells(iRow, iCol)
  29.          DoCmd.Hourglass True
  30.          iFld = iFld + 1
  31.  
  32.  
  33.       Next
  34.  
  35.  
  36.  
  37.    If iFld = 22 Then
  38.    rst("Date").value = wks.Cells(3, 3)
  39.    End If
  40.  
  41.       iRow = iRow + 1
  42.       rst.Update
  43.       rst.AddNew
  44.  
  45.  
  46.    Loop
  47.  
  48.    rst.Close
  49.    Set rst = Nothing
  50.  
  51.  
Jan 26 '11 #3

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

Similar topics

1
by: SD | last post by:
Hi, This is driving me nuts, I have a table that stores notes regarding an operation in an IMAGE data type field in MS SQL Server 2000. I can read and write no problem using Access using the...
2
by: Rolf | last post by:
Hi all, I Have a web page wich displays some data from an access DB using the Datalist control. I have 1 problem with a field of the type Data/Time. When I display the field using <%#...
2
by: Wayne | last post by:
How does Access determine how many data points it will use in a chart and is there any way of forcing it to use more data points? My Access chart is only showing 7 data points of the 100+ that are...
0
by: bluewave | last post by:
how to Demonstration data a field ms access inside a listbox?
1
by: shaguna.dhall | last post by:
I need to migrate Unicode data from MS Access to Oracle. Have tried the following: -Exported the Access tables to csv/txt, but these files were generated in ANSI encoding, and the Unicode data...
2
by: rajaaryan44 | last post by:
how can we transfer data from one access database to another databse . the table name is same for both the database . in one table some records are there (rs say e.g.) now another table has say rs+10...
0
by: JP | last post by:
Hello: I am using VB 6.0 with a Windows XP Professional environment. I am also using Access 2000. I am currently building a program and need reporting capabilities. So, I started a Data...
1
by: ritu raj shriwastaw | last post by:
I am using window xp and php trait(php3.1,mysql4.2).i have one field is of memo data type and I am unable to retrieve data from that memo data type field. what query I should write?
1
by: dkriese | last post by:
I am using Quickbooks reporting tool that can export an xls or csv file. The data being exported needs to create a classroom scheduler. The data being exported is from a sales receipt via QB and...
1
by: Michael Fuller | last post by:
We are currently searching for a solution to manage data. We have a bunch of laboratory and field analytical data in an Access 2003 database. We also have some plant process data that is recorded...
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: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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?
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.