943,708 Members | Top Members by Rank

Ad:
Jul 23rd, 2008
0

how to update the text file into access file

Expand Post »
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
can anyone help... me.. very urgent...
Last edited by Tekmaven; Jul 24th, 2008 at 3:11 am. Reason: Code tags
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
vbgirl is offline Offline
13 posts
since Jul 2008
Jul 23rd, 2008
0

Re: how to update the text file into access file

Hi, I cannot understand completely, but i guess your problem
VB Syntax (Toggle Plain Text)
  1. For i = 0 To b - 1
  2. Do While Not .EOF
  3. If ProductID(i) = rsId.Fields("ID") Then
  4. 'Update Your Field Here
  5. 'Ex rsId.Field ("Field Name") = a ( i )
  6. rsId.Update
  7. End If
  8. rsId.MoveNext
  9. Loop
  10. rsId.MoveFirst
  11. Next

or Simply Use UPDATE SQL

Please Specify Further informations
Your TextFile Format and Database Table Fields to be Updated.
Reputation Points: 44
Solved Threads: 101
Posting Pro
selvaganapathy is offline Offline
547 posts
since Feb 2008
Jul 23rd, 2008
0

Re: how to update the text file into access file

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?
Reputation Points: 10
Solved Threads: 0
Newbie Poster
vbgirl is offline Offline
13 posts
since Jul 2008
Jul 23rd, 2008
0

Re: how to update the text file into access file

Only New data, Not Existing?. I thought the red indicated is ID and Second one is SubField. Also i thought If ID exists then You should update the DB. I dont know what happens when ProductID Not Exists?
Reputation Points: 44
Solved Threads: 101
Posting Pro
selvaganapathy is offline Offline
547 posts
since Feb 2008
Jul 24th, 2008
0

Re: how to update the text file into access file

yes only new data will update to access
then how the code write?
Reputation Points: 10
Solved Threads: 0
Newbie Poster
vbgirl is offline Offline
13 posts
since Jul 2008
Jul 24th, 2008
0

Re: how to update the text file into access file

i only want the red color will update to access file
Reputation Points: 10
Solved Threads: 0
Newbie Poster
vbgirl is offline Offline
13 posts
since Jul 2008
Jul 24th, 2008
0

Re: how to update the text file into access file

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
VB Syntax (Toggle Plain Text)
  1. For i = 0 To b - 1
  2. On Error Resume Next
  3. rsId.AddNew
  4. rsId(0) = ProductID(i)
  5. rsId.Update
  6. Next
Dont forget to set the primary key
Reputation Points: 44
Solved Threads: 101
Posting Pro
selvaganapathy is offline Offline
547 posts
since Feb 2008
Jul 25th, 2008
0

Re: how to update the text file into access file

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
VB Syntax (Toggle Plain Text)
  1. For i = 0 To b - 1
  2. On Error Resume Next
  3. rsId.AddNew
  4. rsId(0) = ProductID(i)
  5. rsId.Update
  6. Next
Dont forget to set the primary key

ok.. thanks..
i done it...
Reputation Points: 10
Solved Threads: 0
Newbie Poster
vbgirl is offline Offline
13 posts
since Jul 2008
Jul 25th, 2008
0

Re: how to update the text file into access file

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
VB Syntax (Toggle Plain Text)
  1. For i = 0 To b - 1
  2. On Error Resume Next
  3. rsId.AddNew
  4. rsId(0) = ProductID(i)
  5. rsId.Update
  6. Next
Dont forget to set the primary key
but this only udate one 1 data only?
Reputation Points: 10
Solved Threads: 0
Newbie Poster
vbgirl is offline Offline
13 posts
since Jul 2008

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in Visual Basic 4 / 5 / 6 Forum Timeline: What is difference between Module and Functions
Next Thread in Visual Basic 4 / 5 / 6 Forum Timeline: why the code only show out one data when update?





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC