Click here to Skip to main content
15,905,679 members
Home / Discussions / Visual Basic
   

Visual Basic

 
GeneralRe: dataRows, dataCols, etc...? Pin
kowplunk9-Aug-04 6:10
kowplunk9-Aug-04 6:10 
QuestionHow to implement right click event on MenuItem of Mainmenu in vb.net? Pin
viettho3-Aug-04 13:43
viettho3-Aug-04 13:43 
AnswerRe: How to implement right click event on MenuItem of Mainmenu in vb.net? Pin
Dave Kreskowiak4-Aug-04 4:37
mveDave Kreskowiak4-Aug-04 4:37 
GeneralMMControl Help Pin
Red Sunday3-Aug-04 12:36
Red Sunday3-Aug-04 12:36 
GeneralRe: MMControl Help Pin
Dave Kreskowiak4-Aug-04 3:33
mveDave Kreskowiak4-Aug-04 3:33 
GeneralRe: MMControl Help Pin
Red Sunday4-Aug-04 7:54
Red Sunday4-Aug-04 7:54 
GeneralRe: MMControl Help Pin
Dave Kreskowiak4-Aug-04 10:48
mveDave Kreskowiak4-Aug-04 10:48 
Generaloverwrite a mdb file Pin
kornstyle3-Aug-04 12:26
kornstyle3-Aug-04 12:26 
I found some vb script code on the internet that can convert a comma delimited text file into an mdb file. Here is the code.



--------------------------------------------------------------------------
'NBM 04/10/2001

'Declare constants
Const Jet10 = 1
Const Jet11 = 2
Const Jet20 = 3
Const Jet3x = 4
Const Jet4x = 5

'Routine to create MDB file.
Sub createNewMDB(FileName, Format)
Const adInteger = 3
Const adVarWChar = 202
Const adVarChar = 200
Const adCollNullable = 2

Dim Catalog
Set Catalog = CreateObject("ADOX.Catalog")

Catalog.Create "Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Jet OLEDB:Engine Type=" & Format & _
";Data Source=" & FileName

Dim objListTable, objColumn
Set objListTable = CreateObject("ADOX.Table")

objListTable.Name = "List"
objListTable.Columns.Append "TestCount", adVarWChar, 40
objListTable.Columns.Append "TestTime", adVarWChar, 50
objListTable.Columns.Append "TestDate", adVarWChar, 50
objListTable.Columns.Append "SerialNumber", adVarWChar, 50
objListTable.Columns.Append "CylinderSize", adVarWChar, 40
objListTable.Columns.Append "CylinderService", adVarWChar, 30
objListTable.Columns.Append "CylinderManufacturer", adVarWChar, 10
objListTable.Columns.Append "DOTRating", adVarWChar, 35
objListTable.Columns.Append "TestPressure", adVarWChar, 30
objListTable.Columns.Append "ActualPressure", adVarWChar, 20
objListTable.Columns.Append "TestDuration", adVarWChar, 20
objListTable.Columns.Append "TotalExpansion", adVarWChar, 45
objListTable.Columns.Append "PermExpansion", adVarWChar, 45
objListTable.Columns.Append "PercentPermanentExpansion", adVarWChar, 45
objListTable.Columns.Append "ElasticExpansion", adVarWChar, 45
objListTable.Columns.Append "REE", adVarWChar, 45
objListTable.Columns.Append "Disposition", adVarWChar, 45
objListTable.Columns.Append "PlusStar", adVarWChar, 45
objListTable.Columns.Append "Remarks", adVarWChar, 45
objListTable.Columns.Append "CylinderOwner", adVarWChar, 45
objListTable.Columns.Append "NotKnown", adVarWChar, 45
objListTable.Columns.Append "Source", adVarWChar, 45
objListTable.Columns.Append "ManufactureDate", adVarWChar, 45
objListTable.Columns.Append "Unit", adVarWChar, 45

For Each objColumn in objListTable.Columns
objColumn.Attributes = adCollNullable
Next

Catalog.Tables.Append objListTable

End Sub


Sub convertCSVtoMDB(AccessFile, CSVFile)

Const adOpenStatic = 3
Const adLockReadOnly = 1
Const adCmdText = &H0001
Const adOpenDynamic = 2
Const adLockOptimistic = 3

Dim fso, FileCSV
Set fso = CreateObject("Scripting.FileSystemObject")
Set FileCSV = fso.GetFile(CSVFile)

Dim objConn, objRs
Set objConn = CreateObject("ADODB.Connection")
objConn.Open "Driver={Microsoft Text Driver (*.txt; *.csv)};" & _
"Dbq=" & FileCSV.ParentFolder & ";" & _
"Extensions=asc,csv,tab,txt;" & _
"Persist Security Info=False"

Set objRs = CreateObject("ADODB.Recordset")
objRs.Open "Select * From " & FileCSV.Name, objConn, adOpenStatic, adCmdText


Dim objAccessConn, objAccessRs
Set objAccessConn = CreateObject("ADODB.Connection")
objAccessConn.Open "Driver={Microsoft Access Driver (*.mdb)};" &_
"Dbq=" & AccessFile & ";" & _
"Uid=Admin;" &_
"Pwd=;"


Set objAccessRs = CreateObject("ADODB.Recordset")
objAccessRs.Open "List",objAccessConn,adOpenDynamic,adLockOptimistic


Do While Not objRS.EOF

objAccessRs.AddNew

objAccessRs("TestCount") = objRs("TestCount")
objAccessRs("TestTime") = objRs("TestTime")
objAccessRs("TestDate") = objRs("TestDate")
objAccessRs("SerialNumber") = objRs("SerialNumber")
objAccessRs("CylinderSize") = objRs("CylinderSize")
objAccessRs("CylinderService") = objRs("CylinderService")
objAccessRs("CylinderManufacturer") = objRs("CylinderManufacturer")
objAccessRs("DOTRating") = objRs("DOTRating")
objAccessRs("TestPressure") = objRs("TestPressure")
objAccessRs("ActualPressure") = objRs("ActualPressure")
objAccessRs("TestDuration") = objRs("TestDuration")
objAccessRs("TotalExpansion") = objRs("TotalExpansion")
objAccessRs("PermExpansion") = objRs("PermExpansion")
objAccessRs("PercentPermanentExpansion") = objRs("PercentPermanentExpansion")
objAccessRs("ElasticExpansion") = objRs("ElasticExpansion")
objAccessRs("REE") = objRs("REE")
objAccessRs("Disposition") = objRs("Disposition")
objAccessRs("PlusStar") = objRs("PlusStar")
objAccessRs("Remarks") = objRs("Remarks")
objAccessRs("CylinderOwner") = objRs("CylinderOwner")
objAccessRs("NotKnown") = objRs("NotKnown")
objAccessRs("Source") = objRs("Source")
objAccessRs("ManufactureDate") = objRs("ManufactureDate")
objAccessRs("Unit") = objRs("TotalExpansion")

objAccessRs.Update

objRS.MoveNext
Loop

objAccessRs.Close
objAccessConn.Close
objRs.Close
objConn.Close

Set objAccessRs = Nothing
Set objAccessConn = Nothing
Set objConn = Nothing
Set objRs = Nothing

End sub


'Create Access2000 database
createNewMDB "c:\Program Files\csvdata\template.mdb", Jet4x
'Convert the CSV into the newly created MDB file.
convertCSVtoMDB "c:\Program Files\csvdata\template.mdb", "c:\Program Files\csvdata\export.csv"



--------------------------------------------------------------------------




When I run the code the export.csv file is converted into the template.mdb file. If the template.mdb file from the previous time that the code was run has not been deleted an error message "The database already exists". So I have to delete the mdb file everytime that I run the code.

I was wondering if there was a way that someone could explain to me, so that I would not have to delete the mdb file everytime? In other words the code would simply overwrite the mdb file. Is this possible? Could someone help me?

Thanks.
GeneralRe: overwrite a mdb file Pin
Dave Kreskowiak4-Aug-04 3:08
mveDave Kreskowiak4-Aug-04 3:08 
GeneralRe: overwrite a mdb file Pin
kornstyle4-Aug-04 3:54
kornstyle4-Aug-04 3:54 
GeneralPopulating dropdown in client side. Pin
mittalpa3-Aug-04 11:07
mittalpa3-Aug-04 11:07 
GeneralRe: Populating dropdown in client side. Pin
Dave Kreskowiak4-Aug-04 3:00
mveDave Kreskowiak4-Aug-04 3:00 
Generalscreen shot and Remoting Pin
tommy_tanaka3-Aug-04 8:17
tommy_tanaka3-Aug-04 8:17 
GeneralHighlight a cell in DataGrid Pin
Richard Jones3-Aug-04 8:00
Richard Jones3-Aug-04 8:00 
Generalcommunication port Pin
x_no3-Aug-04 0:07
x_no3-Aug-04 0:07 
GeneralRe: communication port Pin
Dave Kreskowiak3-Aug-04 5:17
mveDave Kreskowiak3-Aug-04 5:17 
Generaladding a new node to XML config file Pin
Vineet Rajan2-Aug-04 20:57
Vineet Rajan2-Aug-04 20:57 
GeneralPlz Help me to fix overflow error Pin
Murtuza Husain Miyan Patel2-Aug-04 20:08
professionalMurtuza Husain Miyan Patel2-Aug-04 20:08 
GeneralRe: Plz Help me to fix overflow error Pin
Dave Kreskowiak3-Aug-04 5:21
mveDave Kreskowiak3-Aug-04 5:21 
GeneralRe: Plz Help me to fix overflow error Pin
Murtuza Husain Miyan Patel3-Aug-04 20:44
professionalMurtuza Husain Miyan Patel3-Aug-04 20:44 
GeneralRe: Plz Help me to fix overflow error Pin
Dave Kreskowiak4-Aug-04 2:57
mveDave Kreskowiak4-Aug-04 2:57 
GeneralRe: Plz Help me to fix overflow error Pin
Murtuza Husain Miyan Patel16-Aug-04 20:05
professionalMurtuza Husain Miyan Patel16-Aug-04 20:05 
GeneralRe: Plz Help me to fix overflow error Pin
Dave Kreskowiak18-Aug-04 1:42
mveDave Kreskowiak18-Aug-04 1:42 
GeneralRe: Plz Help me to fix overflow error Pin
Murtuza Husain Miyan Patel18-Aug-04 4:12
professionalMurtuza Husain Miyan Patel18-Aug-04 4:12 
Generaladding a form to windows service project Pin
Vineet Rajan2-Aug-04 18:31
Vineet Rajan2-Aug-04 18:31 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.