| | |
how to update the text file into access file
Please support our Visual Basic 4 / 5 / 6 advertiser: Programming Forums - DaniWeb Sister Site
![]() |
•
•
Join Date: Jul 2008
Posts: 13
Reputation:
Solved Threads: 0
Public cnName As Connection
Public rsId As Recordset
Private Sub cmdImport_Click()
Dim a(50) As String
Dim ProductID(50) As String
Dim i As Integer
i = 0
cdbOpenFile.Filter = "Text Files (*.txt)|*.txt| "
'Specify default file name to open
cdbOpenFile.FileName = ""
' Specify default filter to *.txt
cdbOpenFile.FilterIndex = 1
' Display the Open dialog box, and
' save the selected file in the
' variable FileSelect
cdbOpenFile.ShowOpen
Open cdbOpenFile.FileName For Input As #1
Do Until EOF(1)
Line Input #1, a(i)
ProductID(i) = UCase(Left(a(i), InStr(a(i), ",") - 1))
a(i) = Mid(a(i), Len(ProductID(i)) + 1, Len(a(i)))
'MsgBox ProductID(i), vbOKOnly, "Text File"
i = i + 1
Loop
Close #1
Dim b As Integer
b = i
Path = App.Path
Set cnName = New ADODB.Connection
With cnName
.CursorLocation = adUseClient
.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & Path & "\name.mdb;Persist Security Info=False;Jet OLEDB"
.Open
End With
Set rsId = New ADODB.Recordset
rsId.Open "ID", cnName, adOpenKeyset, adLockOptimistic
'With rsId
'.MoveFirst
'While Not .EOF
'MsgBox .Fields(0), vbOKOnly, "Access file"
'.MoveNext
'Wend
'End With
With rsId
.MoveFirst
Dim d As Integer
d = 0
For i = 0 To b
Do While Not .EOF
If ProductID(d) = rsId.Fields(0) Then
rsId.Update
End If
rsId.MoveNext
Loop
rsId.MoveFirst
d = d + 1
Next
End With
'when data done all will show a message box "DONE"
'MsgBox "Done", vbOKOnly + vbInformation, "Complete"
End Sub Last edited by Tekmaven; Jul 24th, 2008 at 3:11 am. Reason: Code tags
Hi, I cannot understand completely, but i guess your problem
or Simply Use UPDATE SQL
Please Specify Further informations
Your TextFile Format and Database Table Fields to be Updated.
VB Syntax (Toggle Plain Text)
For i = 0 To b - 1 Do While Not .EOF If ProductID(i) = rsId.Fields("ID") Then 'Update Your Field Here 'Ex rsId.Field ("Field Name") = a ( i ) rsId.Update End If rsId.MoveNext Loop rsId.MoveFirst Next
or Simply Use UPDATE SQL
Please Specify Further informations
Your TextFile Format and Database Table Fields to be Updated.
KSG
•
•
Join Date: Jul 2008
Posts: 13
Reputation:
Solved Threads: 0
1234567,08072008
8767768,08072008
9988776,08072008
7891234,09072008
4567891,10072008
5213789,11072008
7854123,11072008
4561237,14072008
7879145,15072008
5218510,16072008
this is my text file data.. i would like to take this the read color (if have new data will update to access file)
can you help me change my code?
8767768,08072008
9988776,08072008
7891234,09072008
4567891,10072008
5213789,11072008
7854123,11072008
4561237,14072008
7879145,15072008
5218510,16072008
this is my text file data.. i would like to take this the read color (if have new data will update to access file)
can you help me change my code?
You have to update or Add only one Field (ID field).
> Then set the primary key for the Field.
> Now try to add the Field
> IF the field already Exists then It will cause error and Skip this Error
> and Update The next ID
Your Code
Dont forget to set the primary key
> Then set the primary key for the Field.
> Now try to add the Field
> IF the field already Exists then It will cause error and Skip this Error
> and Update The next ID
Your Code
VB Syntax (Toggle Plain Text)
For i = 0 To b - 1 On Error Resume Next rsId.AddNew rsId(0) = ProductID(i) rsId.Update Next
KSG
•
•
Join Date: Jul 2008
Posts: 13
Reputation:
Solved Threads: 0
•
•
•
•
You have to update or Add only one Field (ID field).
> Then set the primary key for the Field.
> Now try to add the Field
> IF the field already Exists then It will cause error and Skip this Error
> and Update The next ID
Your Code
Dont forget to set the primary keyVB Syntax (Toggle Plain Text)
For i = 0 To b - 1 On Error Resume Next rsId.AddNew rsId(0) = ProductID(i) rsId.Update Next
ok.. thanks..
i done it...
•
•
Join Date: Jul 2008
Posts: 13
Reputation:
Solved Threads: 0
•
•
•
•
You have to update or Add only one Field (ID field).
> Then set the primary key for the Field.
> Now try to add the Field
> IF the field already Exists then It will cause error and Skip this Error
> and Update The next ID
Your Code
Dont forget to set the primary keyVB Syntax (Toggle Plain Text)
For i = 0 To b - 1 On Error Resume Next rsId.AddNew rsId(0) = ProductID(i) rsId.Update Next
![]() |
Similar Threads
- Updating a record in an MS Access database file using DataSets (VB.NET)
- conversion of text file into data base file (Visual Basic 4 / 5 / 6)
- Help with Dataset update (VB.NET)
- Beginners help to migrate from Access to MS SQL fomr VB (Visual Basic 4 / 5 / 6)
- File Processing C++ (C++)
- A agntsrvc.exe file error (Viruses, Spyware and other Nasties)
- I Cannot Delete, Move, or Rename a File On My PC. (Viruses, Spyware and other Nasties)
- vb6/common dialog/access db (Visual Basic 4 / 5 / 6)
- Hotoffers get me mad !! (Viruses, Spyware and other Nasties)
Other Threads in the Visual Basic 4 / 5 / 6 Forum
- Previous Thread: What is difference between Module and Functions
- Next Thread: why the code only show out one data when update?
| Thread Tools | Search this Thread |
* 6 429 2007 access activex add age append application basic beginner birth bmp calculator cd cells.find click client code college column component connection connectionproblemusingvb6usingoledb copy creat ctrl+f data database datareport date delete dissertations dissertationthesis dissertationtopic edit error excel excelmacro file filename form hardware header iamthwee image inboxinvb internetfiledownload keypress label listbox listview liveperson login looping machine microsoft movingranges number objectinsert open oracle password prime program prompt range-objects readfile reading record refresh remotesqlserverdatabase report retrieve save search sendbyte sites sort sql sql2008 sqlserver subroutine table tags textbox time urldownloadtofile vb vb6 vb6.0 vba visual visualbasic visualbasic6 web window windows





