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

How to skip two columns in an Excelsheet when transferring data into Access?

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 is the code:

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.    Dim wbk As New Excel.Workbook
  3.    Dim ExcelApp As New Excel.Application
  4.    Dim ExcelBook As New Excel.Workbook
  5.    Dim wks As New Excel.Worksheet
  6.    Dim rngDefine As Excel.Range
  7.  
  8.    ' Access object variables
  9.    Dim dbs As DAO.Database
  10.    Dim rst As DAO.Recordset
  11.    Dim sSQL As String
  12.  
  13.    Dim lRecords As Long
  14.    Dim iRow As Integer
  15.    Dim iCol As Integer
  16.    Dim iFld As Integer
  17.  
  18.   Set ExcelBook = ExcelApp.Workbooks.Open(sFile)
  19.  
  20.      Set wbk = ExcelApp.Workbooks.Open(sFile)
  21.      Set wks = ExcelApp.Worksheets(cTab1)
  22.  
  23.  
  24.  Set dbs = CurrentDb
  25.    sSQL = "SELECT * FROM " & sTable
  26.    Set rst = dbs.OpenRecordset(sSQL)
  27.  
  28.    With rst
  29.    .AddNew
  30.    End With
  31.  
  32.    iCol = cStartColumn1
  33.    iRow = cStartRow1
  34.  
  35.    Do While Not wks.Cells(iRow, 1) = ""
  36.  
  37.    cStartField1 = rst.Fields(0)
  38.      iFld = cStartField1
  39.       lRecords = lRecords + 1
  40.  
  41.    For iCol = cStartColumn1 To cStartColumn1 + (rst.Fields.Count - (cStartField1 + 1))
  42.  
  43.          rst.Fields(iFld) = wks.Cells(iRow, iCol)
  44.          DoCmd.Hourglass True
  45.          iFld = iFld + 1                  
  46.       Next
  47.  
  48.    If iFld = 22 Then
  49.    rst("Date").value = wks.Cells(3, 3)
  50.    End If
  51.  
  52.       iRow = iRow + 1
  53.       rst.Update
  54.       rst.AddNew
  55.  
  56.  
  57.    Loop
  58.  
  59.    rst.Close
  60.    Set rst = Nothing
  61.  
  62.  
Jan 26 '11 #1
0 921

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

Similar topics

1
by: r_burgess | last post by:
I am looking for some guidance on transferring data between two pages in my ASP.net Web app (intranet). I have a form that will have a button and a text box on it (among other controls of course)...
0
by: Dave | last post by:
I am trying to develop Data Access Pages (DAP) within Access 2003, specifically using Pivot Table Lists. When creating pivot tables as forms, all of my records in a table consisting of over 18,000...
3
by: phong.lee | last post by:
Hello all, i'm new at this. I need some assistant in transferring data from excel to access. I created a macro that basically gather all the necessary data that i need to bring into access. I...
15
by: http://www.visual-basic-data-mining.net/forum | last post by:
Does anyone have any idea how to transferring data from TextBox1 in form1 to textBox2 in form2..... That means after i fill in any data in textBox1 and click Next button... It will bring me to...
2
by: John | last post by:
Hi vs2005/sql server2004. I have created a simple winform app by dragging a table on a winform. I have used stored procedures for data access. I have the following questions; 1. Using the...
3
by: =?Utf-8?B?UGV0ZXI=?= | last post by:
I'm confused about Data Access Layer and Data Object Layer. How are they related? Which layer will be affected when the underlying database structure is changed? Which layer will be affect when...
2
hsriat
by: hsriat | last post by:
I have a page working on Ajax. The problem is, after doing many changes using Ajax (like uploading, changing name, adding to favorites etc), the status bar starts behaving unexpectedly. Even when...
3
by: angusfreefa | last post by:
Dear All, I am facing a problem of transferring data between 2 tables within the same database. I set up 2 tables. The first table is the permanent table (oos_table) for saving records. the...
35
computerfox
by: computerfox | last post by:
I'm writing a work order system using PHP and MySQL and I'm stuck on two things-transferring data and updating the data. Here is my code: i'm using checklogin.php to do most of everything so...
2
emibt08
by: emibt08 | last post by:
Hi, I have an application that I recently revised. It transfers data between 2 programs, including files as well as small data chunks. I never had a problem (got garbage at the other side) or...
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
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
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...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

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.