Hello,
I am a beginner in coding with
VB 6.0. While i tried to learn how to fetch data from Database into a UI form by SQL Queries, i tried the following code with a text file (myTable.txt) being used as data source which is kept under the path C:\DB.
Private Sub Command1_Click()
Dim connectionText As New ADODB.Connection
Dim recordSetObj As New ADODB.Recordset
Dim path As String
path = "C:\DB\"
connectionText.Open "Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" _
& path & ";Extended Properties='text;HDR=YES;FMT=Delimited'"
recordSetObj.Open "Select * From myTable.txt WHERE Year=1977;", _
connectionText, adOpenStatic, adLockReadOnly, adCmdText
Do While Not recordSetObj.EOF
MsgBox recordSetObj(0) & ", " & recordSetObj(1) & ", " & recordSetObj(2)
recordSetObj.MoveNext
Loop
End Sub
I got the above code from the link given below
http://www.ehow.com/way_5568882_visu...-tutorial.html
This code runs perfectly OK when am using text file as database and it fetches the required data into message box too. But when I am using excel as datasource it gives me an error saying the database is read only. I modify the code as below to look up the excel file though.
Private Sub Command1_Click()
Dim connectionText As New ADODB.Connection
Dim recordSetObj As New ADODB.Recordset
Dim path As String
path = "C:\DB\"
connectionText.Open "Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" _
& path & ";Extended Properties='text;HDR=YES;FMT=Delimited'"
recordSetObj.Open "Select * From myTable.
xlsx WHERE Year=1977;", _
connectionText, adOpenStatic, adLockReadOnly, adCmdText
Do While Not recordSetObj.EOF
MsgBox recordSetObj(0) & ", " & recordSetObj(1) & ", " & recordSetObj(2)
recordSetObj.MoveNext
Loop
End Sub
Can i get a help about why this is happening and how to resolve this?