Discussion Locked

Hide subform / requery

0 helpful
5 replies
Closed to new repliesThis discussion is closed. It stays readable, but it takes no new replies.

I posted a question about opening more than one form when a field matched and got the suggestion to create sub forms. IT WORKED GREAT. But then they said this.

(Just set the OnUpdate property of the SSN control on the main form to requery the two subform controls (after you make any appropriate checks to be sure the SSN entered by the user is valid).

You might also want to set the subform controls visible property to false so they are not displayed when the form is opened. After a valid SSN is entered, make them visible and requery them. If an invalid SSN is entered, reset the two subform controls visible property to false.)

I don't get that. How do I hide the subforms until after I input the SSN and then have the subforms appear with the matching information?

Also, they suggested that I put some information in a header. So I can take the SSN field and the other fields that auto populate and put them in the header? Does that mean that will appear in all of the forms? Because each form has the SSN / Name / Phone Number. When I added stuff to the header I couldn't see the sub forms anymore.

It is slow now because I have like 4 sub forms. Will hiding them speed it up?

Oh one last thing. I have dummy ssn's like 000-00-0000 how can I tell it not to pull the history calls for those specific SSN's?

5 replies

by kevin.riggs

I'll take another shot.

One way to handle this is to add a Class Module. Inside the class module, define a Public Sub that performs the actions you want in the order you want them to happen. Then you can call the Class Subs/Functions from the user interface.

An example might be:

Public Sub validSSN()

'refresh method depends on control type

frmSub1.Control1.Refresh
frmSub2.Control1.Refresh
frmSub1.Visible = True
frmSub2.Visible = True

End Sub

Public FunctionisValidSSN(s_SSN as String) As Boolean

isValidSSN = False

Select Case s_SSN
Case "000000000", "999999999", etc
isValid = False
End Select

End Public

The above code goes into the class module. In the form code you could stillperform the query, run the rusulting SSN through the isValid() function (see following) and if the outcome of that is True, then call the validSSN() Sub.

In the form code, use something like:

Private cboSSN_Change() 'Or _LostFocus()

If LenB(cboSSN) = 9 Then
Dim cls_SSN as class_module_name
Dim bIsValidSSN as boolean
bIsValidSSN = class_module_name.isValid(cbo1SSN)
If bIsValidSSN = True Then
Call class_module_name.validSSN()
End If
End If

EndThis should provide some modularity so that you can reuse some of the same calls and it should give you more flexibility in showing/hiding those sub forms.

by bambamz

I GET IT I GET IT.
This was a little bit confusing but only because of my limited knowledge of writing code like this. You are way good at explaining things and since I took the time to really study it and after studying playing around with it, IT WORKS GREAT. I did it a little bit different bcause I am still trying to understand it all but I was able to use the SELECT CASE to tell it after the update of the SSN not to show the history of the dummy SSN's that I had identified. And I figured out the header thing all my myself. Thanks so much for your help

by kevin.riggs

bambmaz,

Just thought of something. I forgot to put the piece of code in that will set isValidSSN() to true. You will have to have that code in the Public function or you would never show the sub forms. Put your SQL statment for pulling the SSN's in the isValidSSN function like below and then test the data that is returned. If nothing is returned based on the SSN entered, then you know that the SSN entered is not valid (at least not for your purposes) and you don't ever set isValidSSN totrue.

Public Function isValidSSN(s_SSN as String) As Boolean

isValidSSN = False

Select Case s_SSN

Case "000000000", "999999999", etc
isValidSSN = False

Case else
Dim sSQL as String
sSQL = "SELECT * FROM database_table . . . ."

'Execute the SQL however you are doing it right now and if the SSN is found, then set isValidSSN to True

If rs.RecordCount > 0 Then

isValidSSN = True

End If

End Select

End Public

This discussion is closed to new replies.