Trying to reverse code that pulls data from table to make it write to the table

sspatriots

Well-known Member
Joined
Nov 22, 2011
Messages
585
Office Version
  1. 365
Platform
  1. Windows
From all the help in the post below from "RoryA", I was able to successfully pull data into a Userform by referencing table column headers:

Is it possible to write code to modify code for new columns?

Now I have attempted to reverse the process to allow the user to select an "Update" button on the Userform and update the table directly from the form using the same code in reverse. However, it is giving me a "Run-time error '424': Object required" message at the line that starts with ".tb.ListColumns...". Not sure what object it is looking for here. Thanks in advance for any attention given to this post.


VBA Code:
Sub Update_Job_Status_Form()


   Dim wb As Workbook
   Dim ws As Worksheet   'Added SPS,06/16/22
   Dim tb As ListObject
   Dim frm As Object    'UserForm
   Dim job_name As String
   Dim i As Long
   
   Set wb = ThisWorkbook
   
   Set ws = wb.Sheets("Jobs") 'Added SPS,06/16/22, worksheet the table is on
   
   Set tb = ws.ListObjects("G2JobList")
   
   Set frm = Job_Status
   
   With frm
   
      job_name = Trim(.txtJobName.Text)
      
      For i = 1 To tb.DataBodyRange.Rows.Count
      
         If tb.ListColumns("Job Name").DataBodyRange.Cells(i).Value = job_name Then
         
           
            .tb.ListColumns("Job" & Chr(10) & "Status").DataBodyRange.Cells(i).Value = cboJobStatus.Text
            .tb.ListColumns("G2" & Chr(10) & "PM").DataBodyRange.Cells(i).Value = txtG2PM.Text
            
            
            Exit For
         
         End If
      
      Next
   
   End With

NumLockCorrector

End Sub
 
Thanks for the information. I will have a look.

I made one more subtle change to those two lines and now it seems to work.

I changed this:

VBA Code:
                    tb.ListColumns("Job" & Chr(10) & "Status").DataBodyRange.Cells(i).Value = cboJobStatus.Text
                    tb.ListColumns("G2" & Chr(10) & "PM").DataBodyRange.Cells(i).Value = txtG2PM.Text


To this:

VBA Code:
                    tb.ListColumns("Job" & Chr(10) & "Status").DataBodyRange.Cells(i).Value = .cboJobStatus.Text
                    tb.ListColumns("G2" & Chr(10) & "PM").DataBodyRange.Cells(i).Value = .txtG2PM.Text

I added the dot in front of the combobox and text box references after the equals sign.


Hopefully that is all I needed. I will continue to fill up the rest of the code with the other textbox references that populate my tables and see how it goes. Thank you for your help. I liked how you use the "Debug.Print" to figure out where the problem was.
 
Upvote 0

Excel Facts

Add Bullets to Range
Select range. Press Ctrl+1. On Number tab, choose Custom. Type Alt+7 then space then @ sign (using 7 on numeric keypad)
if cboJobStatus and txtG2PM are the names of the controls then the "dot" will link them to "With frm" (that hopefully refers to the userform), and that do the job.
(on the contrary we had to remove it in front of tb.ListColumns(etc etc because tb has nothing to do to "With frm")
 
Upvote 0
Solution
Yea, when I reversed them from the original code that pulled the data from the table into the form, I left the dots there. Thanks,
 
Upvote 0

Forum statistics

Threads
1,223,969
Messages
6,175,690
Members
452,667
Latest member
vanessavalentino83

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