This should be simple:
I double click in a text box on a form. The event triggers a public function in a separate module and passes the current form with ME. I want to take the value in the box convert it from feet to meters and return it to the box.
Here's the function:
Public Function Converter(frmCurrentForm As Form)
Dim ctlCurrentControl As Control
Dim strControlName As String
Dim strFormName As String
Dim intControlValue As Integer
strFormName = frmCurrentForm.Name
Set ctlCurrentControl = Screen.ActiveControl
strControlName = ctlCurrentControl.Name
intControlValue = CInt(Screen.ActiveControl)
MsgBox strFormName ' for test - works
MsgBox "current control" & strControlName ' for test - works
intControlValue = intControlValue * 0.3048
Forms!sfrmMDPoint.Controls!Text22.Text = intControlValue ' works
'Forms!strFormName.Controls!strControlName.Text = 99 'doesn't work
'Forms!frmCurrentForm.Controls!ctlCurrentControl.Text = 100 'doesn't work
So i successfully pass the form name, control name and value into the function.
What i can't seem to do is to use these (stored in variables) to access the control - which is key since i'll be calling this from many fields. If i hard code it in it works fine.
I double click in a text box on a form. The event triggers a public function in a separate module and passes the current form with ME. I want to take the value in the box convert it from feet to meters and return it to the box.
Here's the function:
Public Function Converter(frmCurrentForm As Form)
Dim ctlCurrentControl As Control
Dim strControlName As String
Dim strFormName As String
Dim intControlValue As Integer
strFormName = frmCurrentForm.Name
Set ctlCurrentControl = Screen.ActiveControl
strControlName = ctlCurrentControl.Name
intControlValue = CInt(Screen.ActiveControl)
MsgBox strFormName ' for test - works
MsgBox "current control" & strControlName ' for test - works
intControlValue = intControlValue * 0.3048
Forms!sfrmMDPoint.Controls!Text22.Text = intControlValue ' works
'Forms!strFormName.Controls!strControlName.Text = 99 'doesn't work
'Forms!frmCurrentForm.Controls!ctlCurrentControl.Text = 100 'doesn't work
So i successfully pass the form name, control name and value into the function.
What i can't seem to do is to use these (stored in variables) to access the control - which is key since i'll be calling this from many fields. If i hard code it in it works fine.