Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Magical Option Group 1

Status
Not open for further replies.

Accesser

Technical User
Jun 3, 2002
44
US
Hi All,

In a single main form, I've inserted a Yes/No option group (No is default) asking a users if they want to "Enter additional info?"

If a user selects Yes in a particular record, I'd like for the additional info fields (Book, BkPage, BkIndex) to become visible for data entry. And, these fields should then always stay visible for that record. Note that the 3 fields don't all have to contain data. The option group frame (optFrame) also needs to become transparent or invisible (because I plan to place the option group directly over the 3 fields), but maintain its value.

If the user selects Yes, but then happens to LEAVE ALL of the Book, BkPage, BkIndex fields null, the 3 fields should disappear and the option group should reappear with 'No' again selected.

If a user selects Yes in a record, enters data in the 3 fields, then goes to the previous record that, say, was 'No', the option group with No selected should remain visible. If the user returns to the record with data entered for at least 1 of the 3 fields, the 3 fields should be visible. If the user goes to a new record, the option group with No as default should again be visible.

Here is code so far I've come up with for the option group's AfterUpdate event:

Private Sub optFrame_AfterUpdate()
Select Case Me.optFrame

Case 1
Me.Book.Visible = True
Me.BkPage.Visible = True
Me.BkIndex.Visible = True
Me.Book.SetFocus

' not sure about this part; Me.optFrame.Visible = False

Case 2
Me.Book.Visible = False
Me.BkPage.Visible = False
Me.BkIndex.Visible = False

' not sure about this part; Me.optFrame.Visible = True

End Select
End Sub

Here is code so far I've come up with for the form's (record's?) OnCurrent event:

Private Sub Form_Current()

If optFrame.Value = 1 Then
Me.Book.Visible = True
Me.BkPage.Visible = True
Me.BkIndex.Visible = True

' not sure about this part; Me.optFrame.Visible = False

Else
Me.Book.Visible = False
Me.BkPage.Visible = False
Me.BkIndex.Visible = False

' not sure about this part; Me.optFrame.Visible = True

End If
End Sub

Any advice/assistance would be greatly appreciated!!!!
 
Hi

All looks OK, only comments are:

You need code in the On Current Event only to set Option Group visible and the three fields not visible if the three fields are null

You cannot set visible property to false if control has the focus, so youi need aline of code before the .visible = false to move focus of the control in question

Why not put the code you have so far in a Sub or Function and call it, so you do not have to repeat same code in two places, you could include the code to test for null, but make its execution dependant on a parameter

Hope that helps Regards

Ken Reay
Freelance Solutions Developer
Boldon Information Systems Ltd
UK
 
Well, for a start - you don't need an option group.

Replace the option group with a button cmdExtras
command button caption = "Click to add extra data."
Code:
Private Sub cmdExtras_Click()
Book.Visible = True
BkPage.Visible = True
BkIndex.Visible = True
Book.SetFocus
cmdExtras.Visible = False
End Sub

You don't need the Case2 in your original post because if the code runs it is, by definition, setting all the values in the list to the values that they already are.

Code:
Private Sub Form_Current()
SomeOtherControl.SetFocus   ' To guarantee that Focus isn't in a control you are about to make .Visible = False
If IsNull(Book) AND IsNull(BkPake) AND IsNull(BkIndex) Then
    Book.Visible = False
    BkPage.Visible = False
    BkIndex.Visible = False
    cmdExtras.Visible = True
Else
    Book.Visible = True
    BkPage.Visible = True
    BkIndex.Visible = True
    cmdExtras.Visible = False
End If
End Sub



QED.



G LS
accessaceNOJUNK@valleyalley.co.uk
Remove the NOJUNK to use.

Please remember to give helpful posts the stars they deserve!
This makes the post more visible to others in need! :-D

 
Awesome answers!

I was initally playing around with a toggle btn, so I just went with LittleSmudge's code, which works. I was close, but close doesn't count in code.

Later,

Eric
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top