updating access db from excel (1 Viewer)

sunshine076

Registered User.
Local time
Yesterday, 21:12
Joined
Apr 6, 2009
Messages
160
I have written some code and found for the most part that it works up until the code updates an actual line of data form Excel. It will read it but it will not import the line into access.
Code:
Option Explicit

Dim intCOL As Integer
Dim intROW As Integer

Private Sub Worksheet_Change(ByVal Target As Range)
Dim wb As String
Dim myCell As Range

If Not Intersect(Target, Range("$A:$M")) Is Nothing Then
    For Each myCell In Intersect(Target, Range("$A2:$M283"))
        intROW = myCell.Row
        intCOL = myCell.Column
        UpdateDatabase
    Next
End If

Application.EnableEvents = True

End Sub


Private Sub Test()
Dim r As Integer, c As Integer
   intROW = 157
   intCOL = 1
      UpdateDatabase
End Sub


Public Function BottomRow(ColumnNumber As Integer)
   BottomRow = Cells(Rows.Count, ColumnNumber).End(xlUp).Row
End Function


Private Sub UpdateDatabase()
Dim myID As Long
Dim db As Database, rs As Recordset

    Set db = OpenDatabase("Y:\Quality\Databases\eims.mdb")
    Set rs = db.OpenRecordset("M15", dbOpenTable)

    myID = Cells(intROW, 13).Value

    With rs
        Do
            If .Fields("ID") = myID Then
                .Edit
                Select Case intCOL
                Case Is = 1
                   .Fields("CharNum") = Cells(intROW, intCOL)
                    .Update
                    Exit Do
                Case Is = 2
                   .Fields("Desc") = Cells(intROW, intCOL)
                    .Update
                    Exit Do
                Case Is = 3
                   .Fields("OpNum") = Cells(intROW, intCOL)
                    .Update
                    Exit Do
                Case Is = 4
                   .Fields("Loc") = Cells(intROW, intCOL)
                    .Update
                    Exit Do
                Case Is = 5
                   .Fields("LSL") = Cells(intROW, intCOL)
                    .Update
                    Exit Do
                Case Is = 6
                   .Fields("USL") = Cells(intROW, intCOL)
                    .Update
                    Exit Do
                Case Is = 7
                   .Fields("GELSL") = Cells(intROW, intCOL)
                    .Update
                    Exit Do
                Case Is = 8
                   .Fields("GEUSL") = Cells(intROW, intCOL)
                    .Update
                    Exit Do
                Case Is = 9
                   .Fields("lessa") = Cells(intROW, intCOL)
                    .Update
                    Exit Do
                Case Is = 10
                   .Fields("morea") = Cells(intROW, intCOL)
                    .Update
                    Exit Do
                Case Is = 11
                   .Fields("lessb") = Cells(intROW, intCOL)
                    .Update
                    Exit Do
                Case Is = 12
                   .Fields("moreb") = Cells(intROW, intCOL)
                    .Update
                    Exit Do
                End Select
            End If
            rs.MoveNext
        Loop Until rs.EOF
    End With
        Set rs = Nothing
        Set db = Nothing
End Sub
 
Last edited by a moderator:

boblarson

Smeghead
Local time
Yesterday, 18:12
Joined
Jan 12, 2001
Messages
32,059
Use code tags

When you post code, ESPECIALLY long bits of code, please use CODE TAGS to make it more readable.
 

sunshine076

Registered User.
Local time
Yesterday, 21:12
Joined
Apr 6, 2009
Messages
160
sorry about this
 

sunshine076

Registered User.
Local time
Yesterday, 21:12
Joined
Apr 6, 2009
Messages
160
I have found that the code that I have in my initial post does work however, it does not update access when a new line is entered into excel any suggestions?
 
Last edited:

Users who are viewing this thread

Top Bottom