I am trying to establish a databases which uses mere text files as datasources for its tables. This seems to be the only option because I cannot install anything different on corporate PCs. I have tried to use a variety of connection strings to initialize the database (see code below).
I have two issues: firstly, if I manage to connect with strConnectionString2, there is the error that the decimal separator (coma) matches text delimiter (coma). It is NOT an option to change anything in registry because the PCs are heavily protected.
Second issue: if I use ConnectionString3, I get an error message 'Data source name too long'. When I try using a shorter one, it says that the data source cannot be found. The system is 64 bit Windows 7
Any help will be very much appreciated. Alternative methods are also accepted but they cannot involve installing any additional software and changing anything in directory. Changing decimal separator in Excel is not an option as well becuase it mihgt crash down other workflows.
Sub testDatabase()
Dim strDatabaseDirectory As String
Dim strConnectionString1 As String
Dim strConnectionString2 As String
Dim strConnectionString3 As String
Dim dbMurenaDatabase As ADODB.Connection
Dim rcsRecords As ADODB.Recordset
strDatabaseDirectory1 = ThisWorkbook.path & "\database\"
strDatabaseDirectory2 = "Libraries\Documents"
strDatabaseDirectory3 = "C:\db"
strConnectionString1 = "Data Source='" & strDatabaseDirectory & "';Delimiter=';'"
strConnectionString2 = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & strDatabaseDirectory1 & ";" & _
"Extended Properties=""" & "text;HDR=Yes;FMT=Delimited""" & ";"
strConnectionString3 = "Data Source='" & strDatabaseDirectory3 & "';Delimiter=';';" & _
"Has Quotes=True;Skip Rows=0;Has Header=True;Comment Prefix='#';" & _
"Column Type=String,String,String,Int32,Boolean,String,String;" & _
"Trim spaces=False;Ignore Empty Lines=True;"
Set dbMurenaDatabase = New ADODB.Connection
dbMurenaDatabase.Open strConnectionString3
dbMurenaDatabase.Execute "CREATE TABLE [firstTable.txt] (FirstCol TEXT, SecCol TEXT)"
dbMurenaDatabase.Execute "INSERT INTO [firstTable.txt] Values ('smth', 'smth2');"
dbMurenaDatabase.Execute "SELECT * FROM firstTable.txt"
End Sub