dbTalk Databases Forums  

Making a set of fields invisible based on a selection

comp.databases.ms-access comp.databases.ms-access


Discuss Making a set of fields invisible based on a selection in the comp.databases.ms-access forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
Parag
 
Posts: n/a

Default Making a set of fields invisible based on a selection - 03-03-2010 , 07:21 PM






I'm trying to make all my foreign currency fields invisible if the
field "Forex?" is selected as "No".

Can this be done without VB?

I tried writing some VB below but this fails to work - any ideas would
be helpful.

Private Sub
Budget_Requested___Salary___Year_1__FX__BeforeUpda te(Cancel As
Integer)

End Sub

Private Sub Page470_Click()

If tblApplication.secondaryCurrency =! "New Zealand Dollar" then
tblSecondaryLUCurrency.Code.Visible = True else
tblSecondaryLUCurrency.Code.Visible = False

End Sub

Private Sub secondaryCurrency_BeforeUpdate(Cancel As Integer)

End Sub

p.s. I haven't used VB or Access for a while so please bear with me!

Reply With Quote
  #2  
Old   
Salad
 
Posts: n/a

Default Re: Making a set of fields invisible based on a selection - 03-04-2010 , 01:19 AM






Parag wrote:
Quote:
I'm trying to make all my foreign currency fields invisible if the
field "Forex?" is selected as "No".

Can this be done without VB?

I tried writing some VB below but this fails to work - any ideas would
be helpful.

Private Sub
Budget_Requested___Salary___Year_1__FX__BeforeUpda te(Cancel As
Integer)

End Sub

Private Sub Page470_Click()

If tblApplication.secondaryCurrency =! "New Zealand Dollar" then
tblSecondaryLUCurrency.Code.Visible = True else
tblSecondaryLUCurrency.Code.Visible = False

End Sub

Private Sub secondaryCurrency_BeforeUpdate(Cancel As Integer)

End Sub

p.s. I haven't used VB or Access for a while so please bear with me!
I use a syntax like
Me.YourControlName.Visible = _
(tblApplication.secondaryCurrency = "New Zealand Dollar")
that compares to true/false.

I'd also use <> or Not.
tblApplication.secondaryCurrency <> "New Zealand Dollar"
Not (tblApplication.secondaryCurrency = "New Zealand Dollar")

I'm not sure why you'd be attempting to hide a table field like
tblApplication.secondaryCurrency. I'd use a Me or Forms reference and
hide the control on a form or report.
Forms!MainForm!YourControlName.Visible...
Me.YourControlName.Visible...

Reply With Quote
  #3  
Old   
Phil
 
Posts: n/a

Default Re: Making a set of fields invisible based on a selection - 03-04-2010 , 07:37 PM



On 04/03/2010 06:19:17, Salad wrote:
Quote:
Parag wrote:
I'm trying to make all my foreign currency fields invisible if the
field "Forex?" is selected as "No".

Can this be done without VB?

I tried writing some VB below but this fails to work - any ideas would
be helpful.

Private Sub
Budget_Requested___Salary___Year_1__FX__BeforeUpda te(Cancel As
Integer)

End Sub

Private Sub Page470_Click()

If tblApplication.secondaryCurrency =! "New Zealand Dollar" then
tblSecondaryLUCurrency.Code.Visible = True else
tblSecondaryLUCurrency.Code.Visible = False

End Sub

Private Sub secondaryCurrency_BeforeUpdate(Cancel As Integer)

End Sub

p.s. I haven't used VB or Access for a while so please bear with me!

I use a syntax like
Me.YourControlName.Visible = _
(tblApplication.secondaryCurrency = "New Zealand Dollar")
that compares to true/false.

I'd also use <> or Not.
tblApplication.secondaryCurrency <> "New Zealand Dollar"
Not (tblApplication.secondaryCurrency = "New Zealand Dollar")

I'm not sure why you'd be attempting to hide a table field like
tblApplication.secondaryCurrency. I'd use a Me or Forms reference and
hide the control on a form or report.
Forms!MainForm!YourControlName.Visible...
Me.YourControlName.Visible...

Though not exactly what you want, I have a system of either hiding or giving
a new caption to fields on a form or report.

Code is

Function HideFormFields(Frm As Form)

Dim MyDb As Database ' This Database
Dim HiddenQuery As Recordset ' Hidden fields table
Dim SQLStg As String
Dim SFrm As Form
Dim Ctl As Control

Set MyDb = CurrentDb()

'Make all controls visible
For Each Ctl In Frm.Controls
Ctl.Visible = True
Next

SQLStg LStg = "SELECT HideFields.*, TblForm_1.FormName, TblForm.FormName AS
SubForm " SQLStg = SQLStg & "FROM ((CoInfo INNER JOIN TblForm ON CoInfo.CoID
= TblForm.CoID) " SQLStg = SQLStg & "INNER JOIN HideFields ON TblForm.FormID
= HideFields.FormID) " SQLStg = SQLStg & "INNER JOIN TblForm AS TblForm_1 ON
TblForm.MainFormID = TblForm_1.FormID " SQLStg = SQLStg & "WHERE
((CoInfo.Selected =True) " SQLStg = SQLStg & "AND (TblForm_1.FormName = " &
Chr$(34) & Frm.Name & Chr$(34) & "));"

On On Error Resume Next ' Control may not exist especially labels on subforms

' Hide Controls specified bu CoInfo form
Set HiddenQuery = MyDb.OpenRecordset(SQLStg)
With HiddenQuery
Do Until .EOF
If !Hide = True Then
If !FormName = !SubForm Then ' main form
Frm(!Field).Visible = False
Else
Set SFrm = Frm(!SubForm).Form
SFrm(!Field).Visible = False
End If
Else
If !FormName = !SubForm Then ' main form
If If Frm(!Field).ControlType = acLabel Or Frm(!Field).ControlType = acPage
Then Frm(!Field).Caption = !NewCaption
Else
Frm(!Field).Controls(0).Caption = !NewCaption
End If
Else
Set SFrm = Frm(!SubForm).Form
If If SFrm(!Field).ControlType = acLabel Or Frm(!Field).ControlType = acPage
Then SFrm(!Field).Caption = !NewCaption
Else
SFrm(!Field).Controls(0).Caption = !NewCaption
End If
End If
End If
.MoveNext
Loop
.Close
End With

Set HiddenQuery = Nothing
Set MyDb = Nothing

End Function

This may or may not help.

However I am concerned that you are trying to hide fields in a table. Tables
IMO are purely there to store data. Data should only ever be entered through
a form so that error checking cone be done.

Phil

Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.