code not working

TCM1770

Board Regular
Joined
Feb 6, 2005
Messages
121
Office Version
  1. 365
Hi - i have been using this code for some time now on many spreadsheets. I just created another spreadsheet did a copy and paste into a VBA module, edited the .fields to mirror my access table and it will not run. I noticed that the .fields ("") = Range("A" & mrow).Value has this label when i step through the code (f8) (fields ("") = Range("A" & mrow). =(object vairable or with block variable not set) appears.
Below is the code that i am trying to run, can someone look at it and let me know what I am doing wrong? I am using office 07 but needed to write in 2000 - 2003 version.

Sub Users_tomdb()

' open excel file first that you want to export data to the database this goes into the excel module.
Dim mData As String 'this will be the active excel workbook
mData = ActiveWorkbook.Name 'this shows the excel workbook that is active

Dim mrow As Integer 'Counting of rows in sheet to be exported

'Create connection
Dim mConnection As ADODB.Connection
Set mConnection = New ADODB.Connection

'create the link to Access master data file using your connection created.
'You need to specify what drive your data base is on

Dim mtransit_file As String 'This is the name of the database
mtransit_file = "Provider=Microsoft.Jet.oledb.4.0;data Source=" & "\\erdxxxnas000\cccdata\ECMS\S_M\XXX\PC \All_Projects\Turnover\XXX_Web_Access.mdb"
'Open Connection
mConnection.Open ConnectionString:=mtransit_file

'create link to data table. Make sure you name the table in the mRecordset.open " "

Dim mRecordset As ADODB.Recordset
Set mRecordset = New ADODB.Recordset
mRecordset.Open "USERS", mtransit_file, adOpenKeyset, adLockOptimistic

'Get row by row data from import file = excel worksheet

mrow = 2 ' the start row in the worksheet
Do While Len(Range("A" & mrow).Formula) > 0
'repeat until first empty cell in column A
With mRecordset
.AddNew ' create a new record
'add values to each field in the Access Database Record
'("This is where you match the excel column headers to the access data base") .fields(" ")= Range("A" & mrow).Value
.Fields("Renew") = Range("A" & mrow).Value
.Fields("Renew_with_Changes") = Range("B" & mrow).Value
.Fields("Non_Renew") = Range("C" & mrow).Value
.Fields("HIG_EMP Y/N") = Range("D" & mrow).Value
.Fields("Emp_ID") = Range("E" & mrow).Value
.Fields("ACS_User_ID") = Range("F" & mrow).Value
.Fields("Agent_Name") = Range("G" & mrow).Value
.Fields("HIG_EMail_Address") = Range("H" & mrow).Value
.Fields("LOB") = Range("I" & mrow).Value
.Fields("Supervisor") = Range("J" & mrow).Value
.Fields("Supervisor_E-Mail") = Range("K" & mrow).Value
.Fields("Add_Date") = Range("L" & mrow).Value
.Fields("Delete_Date") = Range("M" & mrow).Value
.Fields("Certification_Date") = Range("N" & mrow).Value
.Fields("For_ESG_Use_ONLY_ACSWEBPortal") = Range("O" & mrow).Value
.Update ' stores the new record
End With
mrow = mrow + 1 ' next row
Loop

MsgBox "Your file has been successfully sent to the DataBase."

'Close all links - Clear memory
mRecordset.Close
Set mRecordset = Nothing
mConnection.Close
Set mConnection = Nothing

end sub
 

Excel Facts

What did Pito Salas invent?
Pito Salas, working for Lotus, popularized what would become to be pivot tables. It was released as Lotus Improv in 1989.

Forum statistics

Threads
1,224,585
Messages
6,179,706
Members
452,939
Latest member
WCrawford

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top