p2p.wrox.com Forums

Need to download code?

View our list of code downloads.


Go Back   p2p.wrox.com Forums > Visual Basic > VB 6 Visual Basic 6 > VB Databases Basics
I forgot my password Register Now
Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
VB Databases Basics Beginning-level VB coding questions specific to using VB with databases. Issues not specific to database use will be redirected to other forums.

Welcome to the p2p.wrox.com Forums.

You are currently viewing the VB Databases Basics section of the Wrox p2p Programmer to Programmer discussion community. This is a community of more than 40,000 computer programmers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining our free Wrox p2p community you can post your own programming questions and respond to other programmers’ questions. Registered users also don't have to see the ads that are displayed to guests. Registration is fast, simple and absolutely free so please, join today!
Join today and post to win prizes! Post more to increase your chances of being Wrox’s top poster of the month.

Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old August 16th, 2004, 11:27 AM
Registered User
Points: 32, Level: 1
Points: 32, Level: 1 Points: 32, Level: 1 Points: 32, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Aug 2004
Location: pune, maharashtra, India.
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to belzicool
Default data reading from excel using VB

I am working on a application which needs to read data from a excel file and then, depending on the value, write it to a access file (.mdb)
the problem is that how do i give the condition (till end of file )for the excel sheet
these are the excel and access connections i am using:

Set xlApp = New Excel.Application
xlApp.Workbooks.Open ("E:\nikhil\excel2access\input.xls") 'the excel file is now opened
xlApp.Worksheets("Sheet1").Activate ' the excel worksheet is now active for reading
i = 1
c = 2
Set cn = New Connection
cn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & "E:\nikhil\excel2access\output.mdb;Persist Security Info=False"

cn.Open

cmd.ActiveConnection = cn
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit!
Reply With Quote
  #2 (permalink)  
Old August 16th, 2004, 12:28 PM
Friend of Wrox
Points: 4,754, Level: 29
Points: 4,754, Level: 29 Points: 4,754, Level: 29 Points: 4,754, Level: 29
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Harrisburg, PA, USA.
Posts: 1,998
Thanks: 0
Thanked 3 Times in 3 Posts
Default

Hey,

You can use the VisibleRows property, but that goes all the way to the end of the sheet. I believe I just checked for the presense of values (where cell still has text). I haven't found a way using the API's where you can stop at the end of the data.

Another approach would be to load the excel sheet as a data source (using the DataAdapter) and access it that way.

Brian
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit!
Reply With Quote
  #3 (permalink)  
Old November 25th, 2005, 06:12 AM
Registered User
 
Join Date: Jun 2005
Location: hyd, ap, India.
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi,
first you need to select first cell and then goto last cell
as given below

objExcel.application.Range("A1").Select
objExcel.application.Selection.End(xlDown).Select

so now you are in the last row

objExcel.application.Selection.End(xlToRight).Sele ct

it takes you to last column

then you can find out which row and which column you are in


Tip: If you want to know anything which is possible in EXCEL using VB
Just Record a macro with all the requirements.then study the macro code....thats it...:D

with thanks
Aditya
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit!
Reply With Quote
  #4 (permalink)  
Old December 22nd, 2005, 06:28 AM
PM PM is offline
Registered User
 
Join Date: Dec 2005
Location: , , India.
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi All
Hey Aditya..thats a cool idea.. Here is another way for solving it

'VB.NET code
'To select the used range in WorkSheet
        Dim xlWsheet As Excel.Worksheet = xlApp.Worksheets("Sheet1")
        Dim r As Excel.Range = xlWsheet.UsedRange

' To get the first Value
        MsgBox(r.Cells(1, 1).Value)

' TO get the last value
        MsgBox(r.cells(r.rows.count()-1,r.columns.count()-1).value)


Thanks
PM

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit!
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
data reading from excel using VB.net fly2irfan VB Databases Basics 1 January 27th, 2008 02:35 AM
problem in reading excel data premnaath ASP.NET 2.0 Professional 5 October 22nd, 2007 11:14 AM
Reading and Writing data from Excel using VB? honey123 VB How-To 0 March 25th, 2006 08:48 AM
reading data from excel sheet rajiv_software Classic ASP Basics 2 April 30th, 2005 02:03 AM
Reading Values from Excel cell into VB 6 applicati pratlina Beginning VB 6 2 December 28th, 2004 08:28 AM



All times are GMT -4. The time now is 10:38 PM.


Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
© 2008 Wiley Publishing, Inc