trouble updating a record via userform (run-time error 1004)

kbishop94

Active Member
Joined
Dec 5, 2016
Messages
476
Office Version
  1. 365
Platform
  1. Windows
  2. MacOS
My script that I have so far for finding a specific record and then populating a userform works fine (no errors)

However, when running the command to update the specific record, I run into some trouble... ("run-time error '1004'; application-defined or object-defined error")

Here is the code for locating a specific record:

A combobox is populated with a list from a named range that allows the user to select a specific document name:
(where my named range is "DocNames" and its location is on a worksheet named "List2". cboFN is the name of the combobox on the userform.)

Code:
Private Sub UserForm_Initialize()

Dim cNam As Range
Dim ws1 As Worksheet
Set ws1 = Worksheets("List2")

For Each cNam In ws1.Range("DocNames")
    With Me.cboFN
        .AddItem cNam.Value
    End With
Next cNam
End Sub

then locates whatever document name was selected in the combox cboFN within column C over on the main worksheet:
(where "employee training matrix" is the main worksheet)

Code:
Private Sub cboFN_Exit(ByVal Cancel As MSForms.ReturnBoolean)

    Dim FoundCell As Range
    Dim Search As String

Search = Me.cboFN.Value

Set FoundCell = Worksheets("Employee Training Matrix").Range("C:C").Find(Search, LookAt:=xlWhole, LookIn:=xlValues)

    If Not FoundCell Is Nothing Then
        GetRecord FoundCell.Row
    Else
        MsgBox Search & Chr(10) & "Document: ", 48, " Not Found "
        Me.cboFN.Value = ""
        Cancel = True
    End If

Me.cmdAdd.Enabled = Not Cancel

End Sub

then populates the userform with the data from the specific record that was located:

Code:
Sub GetRecord(ByVal RecordRow As Long)

    Dim ckTYPE As String
    Dim ckDEPT As String
    Dim ckPAR As String
    Dim ckFAC As String
    Dim wx As Worksheet
    Set wx = Worksheets("Employee Training Matrix")

    With Me
        .txtRevDate.Value = wx.Cells(RecordRow, 5)
        .txt24Mo.Value = wx.Cells(RecordRow, 4)
        .txtProRe.Value = wx.Cells(RecordRow, 6)

    On Error Resume Next

    ckTYPE = wx.Cells(RecordRow, 2).Text
    ckDEPT = wx.Cells(RecordRow, 1).Text
    ckPAR = wx.Cells(RecordRow, 8).Text
    ckFAC = wx.Cells(RecordRow, 7).Text

'-"DOCUMENT TYPE" Codes are 3 digits long, all CAPS: "SOP", "WIN", "CUS", "SPC", "REG", "MAN"
'-"FACILITY LOCATIONS" Codes are 3 digits long, all CAPS: "445", "ELC", "239", "529", "TEK", "GFA"
'-"PARENT DEPARTMENT" Codes are 2 digits long, all CAPS: "QM", "FD", "EH", "AG", "TC", "OG"
'
'*********************************************************************************************************
If ckTYPE = "SOP" Then .chk__SOP = True
If ckTYPE = "SOP" Then .lbl__SOP.BackColor = &HFFFF& Else
If ckTYPE = "WIN" Then .chk__WIN = True
If ckTYPE = "WIN" Then .lbl__WIN.BackColor = &HFFFF& Else
If ckTYPE = "CUS" Then .chk__CUS = True
If ckTYPE = "CUS" Then .lbl__CUS.BackColor = &HFFFF& Else
If ckTYPE = "SPC" Then .chk__SPC = True
If ckTYPE = "SPC" Then .lbl__SPC.BackColor = &HFFFF& Else
If ckTYPE = "REG" Then .chk__REG = True
If ckTYPE = "REG" Then .lbl__REG.BackColor = &HFFFF& Else
If ckTYPE = "MAN" Then .chk__MAN = True
If ckTYPE = "MAN" Then .lbl__MAN.BackColor = &HFFFF& Else
'*********************************************************************************************************
If ckPAR = "QMS" Then .chk__QM = True
If ckPAR = "FDA" Then .chk__FD = True
If ckPAR = "EHS" Then .chk__EH = True
If ckPAR = "AGRO" Then .chk__AG = True
If ckPAR = "TECH" Then .chk__TC = True
If ckPAR = "ORG" Then .chk__OG = True
'*********************************************************************************************************
If ckFAC = "445" Then .chk__445 = True
If ckFAC = "445" Then .lbl__445.BackColor = &HFFFF& Else
If ckFAC = "ELC" Then .chk__ELC = True
If ckFAC = "ELC" Then .lbl__ELC.BackColor = &HFFFF& Else
If ckFAC = "529" Then .chk__529 = True
If ckFAC = "529" Then .lbl__529.BackColor = &HFFFF& Else
If ckFAC = "TEK" Then .chk__TEK = True
If ckFAC = "TEK" Then .lbl__TEK.BackColor = &HFFFF& Else
If ckFAC = "GFA" Then .chk__GFA = True
If ckFAC = "GFA" Then .lbl__GFA.BackColor = &HFFFF& Else
'*********************************************************************************************************

so far up to here, everything works fine. the record selected was located, and the userfrom was populated with all the information retrieved from that record (on the worksheet "employee training matrix")

Its only after the user selects the cmdAdd button that it crashes:

Code:
Private Sub cmdAdd_Click()

    Dim wx As Worksheet
    Dim RecordRow As Long
    
    Set wx = Worksheets("Employee Training Matrix")

    Worksheets("Employee Training Matrix").Activate

    RecordRow = Val(Me.cmdNext.Tag)

With wx

' FACILITY CHECKBOXES
If chk__445.Value Then Cells(RecordRow, 7) = "445"
If chk__ELC.Value Then Cells(RecordRow, 7) = "ELC"
If chk__239.Value Then Cells(RecordRow, 7) = "239"
If chk__529.Value Then Cells(RecordRow, 7) = "529"
If chk__TEK.Value Then Cells(RecordRow, 7) = "TEK"
If chk__GFA.Value Then Cells(RecordRow, 7) = "GFA"
' PARENT DEPARTMENT CHECKBOXES
If chk__QM.Value Then Cells(RecordRow, 7) = "QM"
If chk__FD.Value Then Cells(RecordRow, 7) = "FD"
If chk__EH.Value Then Cells(RecordRow, 7) = "EH"
If chk__AG.Value Then Cells(RecordRow, 7) = "AG"
If chk__TC.Value Then Cells(RecordRow, 7) = "TC"
If chk__OG.Value Then Cells(RecordRow, 7) = "OG"
' DOCUMENT TYPE CHECKBOXES
If chk__SOP.Value Then Cells(RecordRow, 2) = "SOP"
If chk__WIN.Value Then Cells(RecordRow, 2) = "WIN"
If chk__CUS.Value Then Cells(RecordRow, 2) = "CUS"
If chk__SPC.Value Then Cells(RecordRow, 2) = "SPC"
If chk__REG.Value Then Cells(RecordRow, 2) = "REG"
If chk__MAN.Value Then Cells(RecordRow, 2) = "MAN" 
'
End With

ActiveWorkbook.Worksheets("Employee Training Matrix").Activate
   Unload Me

End Sub

Here is the error that I get and the highlighted code:

userform5.JPG

Thank you for any help and assistance offered.
 

Excel Facts

Using Function Arguments with nested formulas
If writing INDEX in Func. Arguments, type MATCH(. Use the mouse to click inside MATCH in the formula bar. Dialog switches to MATCH.
What value do you see if you hover your cursor over 'RecordRow' in the yellow highlighted line? Maybe cmdNext.Tag value isn't valid
 
Upvote 0

Forum statistics

Threads
1,223,228
Messages
6,170,875
Members
452,363
Latest member
merico17

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