How to hide fields on forms using vb (1 Viewer)

Angelflower

Have a nice day.
Local time
Yesterday, 18:43
Joined
Nov 8, 2006
Messages
51
Hello fellow developers,

I have two forms that I am working with: The Switchboard and a member/provider listing form. From the switchboard depending on which command button gets clicked opens up the member/provider from. On the member/provider form I have two fields: member field and a provider field. If the member button is selected I want both fields to show up on the member/provider from but if the provider member button is selected then I want only the provider field to show up. I am not sure how to do this. Here is my code so far:

Code behind Switchboard:

If you click get provider info:
Private Sub cmdGetProvider_Click()
'Declare and instantiate the object variables
Dim dbs As Database, qdf As QueryDef, strSQL As String, nodata As String

On Error GoTo Error_Handler

'Set connetion to current database
Set dbs = CurrentDb

'Open the Authorization table by provider name
strSQL = "SELECT DISTINCT DE_fullname as [Provider Name], DE_fedid FROM Authorization " & _
"WHERE DE_effdate<= [Forms]![Menu_NonResidential]![BeginningDate] And DE_termdate >= [Forms]![Menu_NonResidential]![EndingDate] " & _
"And DE_servicecode <>'4010' and DE_servicecode <>'4012' and DE_servicecode <>'4013' and DE_servicecode <>'4015'" & _
"and DE_servicecode <>'4017' and DE_servicecode <>'4018' and DE_servicecode <>'4026' and DE_servicecode <>'4028'" & _
"and DE_servicecode <>'4029' and DE_servicecode <>'4033' and DE_servicecode <>'4036' and DE_servicecode <>'4037';"
'Instantiate a new recordset object
Set qdf = dbs.CreateQueryDef("NonResidentialListing", strSQL)

nodata = Nz(DLookup("DE_fedid", "NonResidentialListing"), "")
If nodata = "" Then
MsgBox "There are no records to display.", vbExclamation, "NO DATA"
DoCmd.DeleteObject acQuery, "NonResidentialListing"
Exit Sub
Else
DoCmd.OpenForm "frmNonResidentialListing"
End If

Exit Sub
Error_Handler:
MsgBox "An error occurred. The error number is " & Err.number & _
" and the description is " & Err.Description
Exit Sub

End Sub


If you click get member info:
Private Sub cmdGetName_Click()
'Declare and instantiate the object variables
Dim dbs As Database, qdf As QueryDef, strSQL As String, nodata As String

On Error GoTo Error_Handler

'Set connetion to current database
Set dbs = CurrentDb

'Open the Authorization table by provider name
strSQL = "SELECT DISTINCT WMIP_Members.DE_memid, WMIP_Members.DE_fullname, Authorization.DE_fullname AS [Provider Name], Authorization.DE_servicecode, WMIP_Members.DE_effdate, WMIP_Members.DE_termdate FROM WMIP_Members " & _
"INNER JOIN Authorization ON WMIP_Members.DE_memid = Authorization.DE_memid " & _
"WHERE WMIP_Members.DE_effdate<= [Forms]![Menu_NonResidential]![BeginningDate] And WMIP_Members.DE_termdate >= [Forms]![Menu_NonResidential]![EndingDate] " & _
"And DE_servicecode <>'4010' and DE_servicecode <>'4012' and DE_servicecode <>'4013' and DE_servicecode <>'4015'" & _
"and DE_servicecode <>'4017' and DE_servicecode <>'4018' and DE_servicecode <>'4026' and DE_servicecode <>'4028'" & _
"and DE_servicecode <>'4029' and DE_servicecode <>'4033' and DE_servicecode <>'4036' and DE_servicecode <>'4037'" & _
"ORDER BY WMIP_Members.DE_fullname;"

'Instantiate a new recordset object
Set qdf = dbs.CreateQueryDef("NonResidentialListing", strSQL)

nodata = Nz(DLookup("DE_memid", "NonResidentialListing"), "")
If nodata = "" Then
MsgBox "There are no records to display.", vbExclamation, "NO DATA"
DoCmd.DeleteObject acQuery, "NonResidentialListing"
Exit Sub
Else
DoCmd.OpenForm "frmNonResidentialListing"
End If

Exit Sub
Error_Handler:
MsgBox "An error occurred. The error number is " & Err.number & _
" and the description is " & Err.Description
Exit Sub

End Sub


Code behind member/proivder from:

Private Sub Form_Close()
DoCmd.DeleteObject acQuery, "NonResidentialListing"
DoCmd.OpenForm "Menu_NonResidential"
End Sub
 

pbaldy

Wino Moderator
Staff member
Local time
Yesterday, 18:43
Joined
Aug 30, 2003
Messages
36,126
In the code after you've opened the form, use:

Forms!frmNonResidentialListing.ControlName.Visible = True '(or False)

It's your call whether you hide them when you design the form and show the ones you want when you open it, or vice-versa.
 

Angelflower

Have a nice day.
Local time
Yesterday, 18:43
Joined
Nov 8, 2006
Messages
51
Thanks! lol... how simiple was that! lol....
 

Users who are viewing this thread

Top Bottom