|
-
Jul 8th, 2004, 02:49 AM
#1
Thread Starter
New Member
Connecting to Excel from VB6(using Excel as a data source)
Iam using Visual Basic 6 and Excel 2000 to create a small Price List. I first tried to do this with VB 6 and Access, but as the Access database got too big gave up on the idea.
The main point I had to consider when creating this application is>
1. B'coz this Interactive Price List had to be sent to clients via e-mail, its size had to be limited below 1MB (including the data)
2. It should be able to work without any network connectivity required, such as accessing the db on a reomte location(server) through the internet using mechanisms such as RDO,ADO.
Therefore I decided on using Excel as it takes 80KB of space where Access takes 3MB+ for the same amount of data.
Question 1. Is there an easier or better way I can acheive my goals?
Question 2. Iam having a small problem with my coding.
Though I have knowledge in SQL strings and DAO,RDO and ADO Iam finding it difficult to get through to Excel data with a somple query in VB 6 using DAO.(I even tried ADO but the error comes in the SQL string I believe)
I have browsed the net for severeal coding samples for this but they all give the same syntax which s giving an error to me and I couldnt figure out whats wrong.
I will give you the coding snippet where I am receiving the error.
>>>>>>>>>>>>>>>
Private Sub Command1_Click()
Dim cn As ADODB.Connection
Dim rs As ADODB.Recordset
Dim sqlstr As String
Set cn = New ADODB.Connection
With cn
.Provider = "Microsoft.Jet.OLEDB.4.0"
.ConnectionString = "Data Source=C:\Documents and Settings\Staff2\My Documents\test2\accessories_test.xls;" & _
"Extended Properties=Excel 8.0;"
.Open
End With
sqlstr = "SELECT * FROM `Sheet1$A1:B10`" """""ERROR comes when this statement is executed
Set rs = cn.OpenRecordset(sqlstr) """""ERROR comes when this statement is executed
'cn.Execute (sqlstr)
While Not rs.EOF
For x = 0 To rs.Fields.Count - 1
Text1.Text = rs.Fields(x).Value
Combo1.AddItem (rs.Fields(x).Value)
Next
rs.MoveNext
Wend
End Sub
<<<<<<<<<<<<<<<<<
I have supplied the ADO connection coding here.
I have even tried >"select * from [Sheet1$A2:A10]" and "SELECT * FROM [Sheet1$] "
for the SQL string to no avail.
And the error I receive is
"Run time error 3001:Arguements are of wrong type, out of acceptable range, or are inconflict with eachother "
My excel workbook takes the format >one sheet named "Sheet1" with a small test data table with field names in the first row and then the data from 2nd row onwards.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|