assigning a value to a variable

Phillip2

Board Regular
Joined
Aug 5, 2019
Messages
79
Office Version
  1. 365
Platform
  1. Windows
I have a worksheet with 100 buttons. Each button represents a Customer’s record number. I’m working on a macro to assign to each button that when clicked would do the following:
  • Open the userform CCX_Form
  • Assign the customer’s record number to the variable TBrecord
  • Run the subroutine Private Sub Search_Click()
My form opens, but I’m getting an error 424 (Object Required) when using the following code. What am I missing?

VBA Code:
Sub Rectangle1_Click()
CCX_Form.Show
TBrecord.Value = "001"
Call Sub Search
End Sub

Thank you in advance for your time and help.
 

Excel Facts

Shade all formula cells
To shade all formula cells: Home, Find & Select, Formulas to select all formulas. Then apply a light fill color.
You need to specify that the textbox is on the userform
VBA Code:
Sub Rectangle1_Click()
With CCX_Form
   .Show
   .TBrecord.Value = "001"
End With
Call Sub Search
End Sub
 
Upvote 0
I tried the code and I’m getting errors on the Call Sub Search line. The first time I got a Syntax error then it began giving me a Compile error: Expected: identifier.

I took that line out and the routine ran without error, but my Record Number textbox (TBrecord) was blank. So, I reversed the order having it set the variable first then showing the form and it worked great.

So I down to the Call Sub Line.

I think my problem with the Search routine is like the one before. The Search routine is inside the form. (The buttons are on a worksheet and their code is written in a module.) I tried moving the Call Sub into the With Statement but that didn’t work.

Any ideas?
 
Upvote 0
Did you try what Snakehips said in post#3?
 
Upvote 0
I did and I got the same error. By the Snakehips I failed to thank you for you input. Things got a little crazy around here.
 
Upvote 0
Why not remove that from the sub & just put Search_Click in the userform_Initalize code
 
Upvote 0
I tried putting Search_Click in the Initialize Code, and it didn't work either. I went back to the original plan and here is a picture if what I'm seeing.
 

Attachments

  • Error.JPG
    Error.JPG
    59.5 KB · Views: 3
Upvote 0
How did you put it in the initialize event?
 
Upvote 0

Forum statistics

Threads
1,214,792
Messages
6,121,612
Members
449,039
Latest member
Mbone Mathonsi

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