Form code not working

CEH

Curtis
Local time
Today, 14:42
Joined
Oct 22, 2004
Messages
1,187
Maybe this should be posted under VBA.... not sure. Havent seen answer that works yet.
Its a form with an option group "PickWO" When you pick an option, different fieilds become visible-non visible. I created a field "PickWOvalue" to store the option value "1" or "2". That part works fine.(visible) The problem is when you reopen the form to view the records the option box value does not show or change the fields visible properties. And the on open cuauses an error. Anyone see the problem?




Private Sub Form_Open(Cancel As Integer)
Me.PickWOvalue.Value = Me.PickWO.Value
End Sub
`````````````````````````````````````
Private Sub PickWO_AfterUpdate()

Call NotVisible

Select Case Me.PickWO

Case Is = 1
Me.ReInspectionDate.Visible = True
Me.Price.Visible = False
Me.WOPreview.Visible = True
Me.PrtWO.Visible = True
Me.WBMInvoice_.Visible = False

Case Is = 2
Me.ReInspectionDate.Visible = False
Me.Price.Visible = True
Me.cmdPreTag.Visible = True
Me.cmdPrtTag.Visible = True
Me.WBMInvoice_.Visible = True


End Select

End Sub
 
CEH,

Try this in the forms Open event:

If Not(IsNull(Me.NameOfTextField)) Then
If Me.NameOfTextField = "1" Then
Me.NameOfOptionGroup = 1
Me.ReInspectionDate.Visible = True
Me.Price.Visible = False
Me.WOPreview.Visible = True
Me.PrtWO.Visible = True
Me.WBMInvoice_.Visible = False
Else
Me.NameOfOptionGroup = 2
Me.ReInspectionDate.Visible = False
Me.Price.Visible = True
Me.cmdPreTag.Visible = True
Me.cmdPrtTag.Visible = True
Me.WBMInvoice_.Visible = True
End If
End If
 
CEH,

I'd imagine that the Option Group does not have a DefaultValue.

You can specify a DefaultValue or you can assign one in the
form's OnOpen event, then force your code to run.

Code:
   Me.YourOptionGroup = 1      ' <-- Don't need if you have a DefaultValue
   YourOptionGroup_AfterUpdate ' <-- Force the AfterUpdate code to run

Wayne
 
Thanks guys... but

neither one of those worked.
 
Hey CEH,

I remember some of the things you were asking from your previous post, about this same option group and was assuming that this option group in unbound. Is it unbound? That was the reason you added a text field [PickWOvalue]. What you were wanting to do is assign the value, from the unbound option group to [PickWOvalue]. Hope I'm right so far.

If all of this is true then I can not see in your After Update code, on your option group, where your assigning the value to [PickWOvalue]. You have different fields visible being used, which will work for that record, but if the value is not stored in [PickWOvalue], then when you change records, you have nothing for Access to go by to make your code work.

In your option groups AfterUpdate event you need to assign a value to [PickWOvalue]

Private Sub PickWO_AfterUpdate()

Call NotVisible

Select Case Me.PickWO

Case Is = 1
Me.PickWOvalue = "1" 'add here
Me.ReInspectionDate.Visible = True
Me.Price.Visible = False
Me.WOPreview.Visible = True
Me.PrtWO.Visible = True
Me.WBMInvoice_.Visible = False

Case Is = 2
Me.PickWO.value = "2" 'and add here
Me.ReInspectionDate.Visible = False
Me.Price.Visible = True
Me.cmdPreTag.Visible = True
Me.cmdPrtTag.Visible = True
Me.WBMInvoice_.Visible = True


End Select

End Sub

Then the code that I gave you for the forms OnOpen event should work for you.

HTH,
Shane
 
Kinda.....

Shane,
I made the control source for the option group (PickWO) the field (PickWOvalue)

I tried adding the whole statement again to the current on the form......

~~~~~~~~

Private Sub Form_BeforeUpdate(Cancel As Integer)
Me.PickWOvalue.Value = Me.PickWO.Value

End Sub

~~~~~~~~~~~~~
Private Sub Form_Current()
If PickWOvalue = "1" Then
Me.ReInspectionDate.Visible = True
Me.Price.Visible = False
Me.WOPreview.Visible = True
Me.PrtWO.Visible = True
Me.WBMInvoice_.Visible = False

ElseIf PickWOvalue = "2" Then

Me.ReInspectionDate.Visible = False
Me.Price.Visible = True
Me.cmdPreTag.Visible = True
Me.cmdPrtTag.Visible = True
Me.WBMInvoice_.Visible = True

End If

End Sub
~~~~~~~~
Private Sub PickWO_AfterUpdate()

Call NotVisible

Select Case Me.PickWO
Case Is = 1

Me.ReInspectionDate.Visible = True
Me.Price.Visible = False
Me.WOPreview.Visible = True
Me.PrtWO.Visible = True
Me.WBMInvoice_.Visible = False

Case Is = 2

Me.ReInspectionDate.Visible = False
Me.Price.Visible = True
Me.cmdPreTag.Visible = True
Me.cmdPrtTag.Visible = True
Me.WBMInvoice_.Visible = True


End Select

End Sub

Private Sub NotVisible()
Dim ctl As Control
For Each ctl In Me
If ctl.Tag = "*" Then
ctl.Visible = False
End If

Next

End Sub
`````````````````````
Everything works now...... But I know this code can be combined into one statement....... Just cant seem to get it to work when I do!!!
 

Users who are viewing this thread

Back
Top Bottom