Calling Userform text_exit sub from Userform cmd_click sub

dloskot

New Member
Joined
Oct 18, 2015
Messages
43
I have a Userform to get data from an access data base. I have all the code written to enter a record id and then get the data from the access data base. I want to have a command button to get next record, but I can't figure out a wall to call the sub that is already written. The sub is of the from

Sub Text_Record_Num_Exit(ByVal Cancel As MSForms.ReturnBoolean)

When I try to do a call to that subroutine I get Runtime error '424' Object Required

Can someone tell me if there is a way the call the text_Exit sub from another sub or a simple way to get the next access record?

Thanks in advance for all the help this forum provides.
 

Excel Facts

Why are there 1,048,576 rows in Excel?
The Excel team increased the size of the grid in 2007. There are 2^20 rows and 2^14 columns for a total of 17 billion cells.
Check if the sub is declared as Private. You will have to explicitly name the module if it is.

Code:
Call Mymodule.Mysub(MyParameters)
 
Upvote 0
I would recommend taking all of the code ran when the "Sub Text_Record_Num_Exit" event is triggered and placing it into a new sub.

Example
Code:
Sub Text_Record_Num_Exit(ByVal Cancel as MSForms.ReturnBoolean)
Call PullData
End Sub

Sub PullData
'...
'...
'Your code pasted here
'...
End Sub
 
Upvote 0
CalcSux78 Yes I though of that but I was trying to reuse the existing code. The problem with your suggestion is if I make a change in the future I would need to make the change in two place. A better suggestion would be to put the main code in a Module sub and call it from the Userform. Again I was trying to get away from extra work when the working code is already written.
 
Last edited:
Upvote 0

Forum statistics

Threads
1,215,532
Messages
6,125,367
Members
449,221
Latest member
chriscavsib

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