[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 543
  • Last Modified:

Passing a control as a parameter, how to simply code

My form has several textboxes to capture timeline events (dates). To control input of the date I am using a activex calendar control object.

The textbox onclick event is used to display the calendar, set the calendars date value to any previously entered date existing in the field or if null current date, and to set the name of the textbox in the calendars .tag property for use in the calendar's onclick event. At this point, code stops pending calendar's on click or lost focus events.

In the on click event of the calendar I use a select case = calendar.tag to then insert the calendar date into which ever textbox the user clicked.

Problem is I may need to requery or manipulate the text box properties (setting lock property etc) after date is entered etc.  I can't figure out how to return to the textbox onclick procedure from the calendars onclick event. Screen.PreviousControl is not useful since focus may change several time is the course of events.  I read about creating a public property or passing the control instead of using a very complicated select case procedure but I can't figure out how to make this work.  Any suggestions would be appreciated.
0
chobe
Asked:
chobe
  • 3
  • 2
  • 2
1 Solution
 
TorrwinCommented:
I don't think you can return to the textbox's OnClick event itself, but you can definitely keep track of which textbox it was using a property.

At the top of your form declare a module-level variable to store the textbox's name in:
Private m_sControlOrigin as String

Then, create the property to be accessed:

Public Property Get ControlOrigin() as String
        ControlOrigin = m_sControlOrigin
End Property

Public Property Let ControlOrigin(ByVal controlName As String)
        m_sControlOrigin = controlName
End Property

In the OnClick even of each of your textboxes, set the value of the variable:
m_sControlOrigin = "MyTextboxName"

To access this from another form it would be:
Forms(MyForm).ControlOrigin
0
 
SimonCommented:
You can call the textbox's onclick event from within the calendar's onclick event like

sub yoursub
'code
'code
call textbox_click()
' more code
end sub

or just textbox_click (without call or the parentheses)


or you can pass the control as an object variable...

'e.g. In a form's class module
sub yoursub
dim objTextbox as control
dim boolSuccess as boolean
set objTextbox = me.txtCompanyname
call doSomething(objTextbox) 'just call if you don't require the return value
'or assign function result to variable
boolSuccess = doSomething(objTextbox)
end sub

function dosomething(ctrl as control)
on error goto Errortrap
    ctrl.visible = true
    ctrl.locked = true
    ctrl.setfocus
    dosomething = true 'return true if no error
    exit function
ErrorTrap:
debug.print err.description
dosomething=false
end function

I'm not sitting in front of Access ATM, but the above should run as an example.
0
 
TorrwinCommented:
To manipulate the controls properties from another form it would be:
Forms(MyForm).Controls(Forms(MyForm).ControlOrigin).Value = ""
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
SimonCommented:
Torrwin's post prompts me to reword mine for clarity..
from
 You can call the textbox's onclick event from within the calendar's onclick event like
to
You can call the textbox's onclick event handler (if you've defined a textbox_Click sub in the form's class module) from within the calendar's onclick event handler.



0
 
chobeAuthor Commented:
Using Simon's code I was able to create the object name, and call myfunc to open the calendar, set the calendar.value to ctrl.value, unlock Ctrl, etc., from the textbox click event, then things fall apart.  Code ends and now I'm left with getting the calendars pick date back to the textbox from the calendar's onclick event....
0
 
TorrwinCommented:
And that's where the code I mentioned comes in handy.  If you have the textbox's name stored in a property, you can access it from your calendar's onclick event.
0
 
chobeAuthor Commented:
Using your suggestion worked great! Very simple...Don't know why first time I accepted your answer did not work but thanks again for the assist!
0

Featured Post

NFR key for Veeam Backup for Microsoft Office 365

Veeam is happy to provide a free NFR license (for 1 year, up to 10 users). This license allows for the non‑production use of Veeam Backup for Microsoft Office 365 in your home lab without any feature limitations.

  • 3
  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now