Link to home
Create AccountLog in
Avatar of Frank Freese
Frank FreeseFlag for United States of America

asked on

reading values from one form into another

Experts,
I have two forms:
frmPreliminaryBonus
frmAdjustmentsToBonus

In frmPreliminaryBonus I have an option group called optSelectEmployee with four check boxes labeled:
ckDM  (value = 1)
ckASM (value = 2)
ckSM (value = 3)
ckAsstSM (value = 4)

In frmAdjustmentToBonus I have an unbound text box called txtEmployee. Nothing assigned to the control source

Here's the code I use in the form load event of frmAdjustmensToBonus
If Form!frmPremilinaryBonus.OptSelectEmployee.ckDM = 1 Then
    Me.txtEmployee = Form!frmPreliminaryBonus.txtDistrictManager
End If

Open in new window

I keep gettin an error Monthly Bonus can't find the field 'frmPreliminaryBonus' referred to in your expression. I need to take the values in frmPreliminaryBonus.txtDistrictManager and assigned it to txt.Employee in my frmAdjustmentsToBonus
Avatar of Rey Obrero (Capricorn1)
Rey Obrero (Capricorn1)
Flag of United States of America image

change Form  to Forms


If Forms!frmPremilinaryBonus.OptSelectEmployee.ckDM = 1 Then
    Me.txtEmployee = Forms!frmPreliminaryBonus.txtDistrictManager
End If
If you check a Value from another Form, that particular Form needs to be open, else it will fail.
So is the Form 'frmPremilinaryBonus' open?

Then the code should be something like this:
If Form!frmPremilinaryBonus.OptSelectEmployee.Value = 1 Then
    Me.txtEmployee = Form!frmPreliminaryBonus.txtDistrictManager
End If

Hope this helps,
Daniel
syntax is:

If this is truely an option group, then you don't need to refer to the checkbox, you refer to the optiongroup to get the value associated with the selected checkbox (of which you can only have one).

The syntax would be:

If Forms!frmPremilinaryBonus.OptSelectEmployee = somevalue


Good point of Capricorn, to make the beginning Forms, missed that! :)

If you check a Value from another Form, that particular Form needs to be open, else it will fail.
So is the Form 'frmPremilinaryBonus' open?

Then the code should be something like this:
If Forms!frmPremilinaryBonus.OptSelectEmployee.Value = 1 Then
    Me.txtEmployee = Forms!frmPreliminaryBonus.txtDistrictManager
End If


is the error

 < Monthly Bonus can't find the field 'frmPreliminaryBonus' referred to in your expression.>

gone when you use ?

If Forms!frmPremilinaryBonus.OptSelectEmployee.ckDM = 1 Then
    Me.txtEmployee = Forms!frmPreliminaryBonus.txtDistrictManager
End If
I've never seen that syntax (trying to refer to a checkbox as though it were a child of an option group work).

When I try that, I get a runtime error #438 (Object doesn't support this property).
if you are checking an Option Group, just use



If Forms!frmPremilinaryBonus.OptSelectEmployee = 1 Then
    Me.txtEmployee = Forms!frmPreliminaryBonus.txtDistrictManager
End If
or do this

Select case Forms!frmPremilinaryBonus.OptSelectEmployee
    case 1
         Me.txtEmployee = Forms!frmPreliminaryBonus.txtDistrictManager

    case 2
        'code here
    case 3
       'code here

    case 4
       'code here

end select
Avatar of Frank Freese

ASKER

I'm in the form Load event:
After I correct a typo the code used is:
If Forms!frmPremilinaryBonus.OptSelectEmployee.ckDM = 1 Then
    Me.txtEmployee = Forms!frmPreliminaryBonus.txtDistrictMgr
End If

Open in new window

and the error code is
Object doesn't support this property or method/
When I use this code:
If Forms!frmPremilinaryBonus.OptSelectEmployee.Value = 1 Then
    Me.txtEmployee = Forms!frmPreliminaryBonus.txtDistrictMgr
End If
 

Open in new window

I get no errors and no data.
When I use this code:
If Forms!frmPreliminaryBonus.OptSelectEmployee = 1 then
 Me.txtEmployee = Forms!frmPreliminaryBonus.txtDistrictMgr
End If

Open in new window

Here I get no error and no data.
That is probably because the value associated with ckDM is not 1.  Open the form in design view, click on the checkbox and look at the data tab of the properties window.  What is the option value associated with the checkbox.

However, if you have checkboxes, that are just laid on top of a option group, then you may actually be able to refer to them as:

Forms!frmPreliminaryBonus.ckDM, in which case the values would probably contain either 0 or -1.

are you sure that the option group "OptSelectEmployee" was created properly ?

to be sure, create the Option group using the wizard .. it is very simple and easy.
I used the wizard but let me do it again just to make sure.
I tried the Case Select which is much better than my plan - no errors - no data?
upload a copy of the db
here you go - thanks. the db opens to the form with the option group.
StoreBonusRevX1.mdb
where is the table " tblEmployeeStatus" ?
didn't notice it was missing - hum? Anyway, I've imported it into this attachment. That's very strange...
StoreBonusRevX1.mdb
ASKER CERTIFIED SOLUTION
Avatar of Rey Obrero (Capricorn1)
Rey Obrero (Capricorn1)
Flag of United States of America image

Link to home
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
See answer
was I kinda of close? that's exactly what I was asking for. Appreciate it very much.
thank you cap:
this solution was accepted because the expert was able to repair the problems and offered up the best solution.