Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Data Retrieving


Hello,

I have one mdb file ("res.mdb") containing the m records x n fields
employee table (tbRes). With the sub RetrieveData (asking for mdb
filename, SQL command and data-destination range), I get the employee
data in a dynamic range of the "employee" worksheet.

My scenario is: the calling sub activates the worksheet and calls the
sub RetrieveData passing the asked parameters

The sub performs correctly.

My problem is this:
I have added one table (tbPassword) in res.mdb, containing only one
field and only one record storing a password the user can modify. In
this case, however, the function fails to retrieve the password value in
the employee worksheet range "M2".

Debugging the code I've seen the recordset.recordcount property equals
-1. Surely something is wrong but I'm not able to understand where and
why.
I've also tried to use the cn and rs.Cursorlocation = 3, but the result
is the same.

SNIPPET OF THE CALLING SUB:
*...

'retrieving the tbres table data
Sheets("employee").activate
mdbfilename = ThisWorkbook.Path & "\res.mdb"

SQLstr = "SELECT tbRes.RepUtil, tbRes.ImpUtil, tbRes.ID,
tbRes.Prof, tbRes.Lastname, " _
& "tbRes.Name FROM tbRes WHERE (((tbRes.Ceased)=False)) ORDER BY
tbRes.Lastname, tbRes.Name"
Call RetrieveData(mdbfilename, SQLstr, "A2")
' the range "A2" populates correctly

'retrieve tbPassword data
SQLstr = "SELECT tbPassword.PSWRD FROM tbTassword;"
Call RetrieveData(mdbfilename, SQLstr, "M2")
....
*


*Public Sub RetrieveData(mdbfilename As String, SQLcmd As String,
destrange As String)
Dim cn As Object
Dim rs As Object
Dim Sh As Worksheet
On Error GoTo err_hnd

Set cn = CreateObject("ADODB.connection")
Set rs = CreateObject("ADODB.recordset")
Set Sh = ActiveSheet

With Sh

'open the connection...
With cn
..CursorLocation = 1
..Provider = "Microsoft.jet.OLEDB.4.0"
..Properties("Data Source") = mdbfilename
..Properties("Jet OLEDB:Database Password") = PWORD
..Open
End With

'populate the recordset
rs.CursorLocation = 1
rs.Open SQLcmd, cn, 1, 3, adCmdText

'popolate sh with the rs records
..Range(destrange).CopyFromRecordset rs

End With

'
Set Sh = Nothing
Set rs = Nothing
Set cn = Nothing
Exit Sub
err_hnd:
MsgBox Err.Description & "/" & Err.Number & " Sub
RecuperaDatiEsterni"
Resume Next
End Sub*


Thanks,


--
eggpap

Emiliano
Excel 2003 on Vista HP System - can use VBA
------------------------------------------------------------------------
eggpap's Profile: http://www.thecodecage.com/forumz/member.php?userid=90
View this thread: http://www.thecodecage.com/forumz/sh...ad.php?t=94944

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
Retrieving Data: Speed of beating down rows vs retrieving from array? (PeteCresswell) Excel Programming 2 July 9th 07 03:30 PM
retrieving data Jess Excel Worksheet Functions 1 February 13th 07 04:54 PM
Retrieving data from the web - help ! glynny Excel Worksheet Functions 0 February 20th 06 02:04 AM
Retrieving Web Data leafsfan1967[_6_] Excel Programming 6 June 25th 05 06:47 PM
Retrieving data Alan M[_2_] Excel Programming 5 March 24th 05 12:27 PM


All times are GMT +1. The time now is 08:42 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"