[AccessD] Problem with Form_Current() - Access 2003 SP3

jwcolby jwcolby at colbyconsulting.com
Mon May 12 07:08:27 CDT 2008


Bob,

First we have to ask if this is a continuous form?  If so this won't 
work at all since in a continuous form you cannot display some fields of 
some records and not others.  I will therefore assume that this is NOT a 
continuous form.

I don't like this kind of "set every control..." method because if the 
controls change your code has to change.

The next method (and simplest) would be to just filter the recordset 
itself such that the records are not even pulled into the recordset if 
the vacant flag is set.

The next suggestion is to use a for each loop and iterate the controls 
collection.  WARNING... this is air code:

function SetVisible(frm as form, blnVisible as boolean) as boolean
on error goto error_handler
dim ctl as control
    for each ctl in frm.controls
	ctl.visible = blnVisible
    next ctl
    SetVisible = true

insert exit code here
insert error handler here

function end

This has the distinct advantage of just adapting as you add or delete 
controls to the form.

Another method that MIGHT work is to simply set the entire section 
visible = false.

None of which addresses the WHY your code fails.  You need to step 
through and see what the value of the CardexVacantFlag  is at the 
instant the current event runs WHERE you expect to hide the controls. 
Obviously the value isn't what you expect or the code would run.


John W. Colby
www.ColbyConsulting.com


Bob Gajewski wrote:
> Hi
>  
> I am having a problem with some Form_Current() code. For an address table, I
> have certain fields that I don't want to display if the VACANT flag is set
> to true. The code works fine in the _AfterUpdate() module, but not in the
> _Current module - and I basically copied from one to the other. I do have
> other display control code in the _Current() module that works fine. Field
> "CardexVacantFlag" is a checkbox with TripleState set to No.
>  
> Any suggestions are gratefully appreciated.
>  
> TIA
> Bob Gajewski
>  
>  
> Private Sub Form_Current()
> If CardexVacantFlag = True Then
>     CardexOccupantLastName.Visible = False
>     CardexOccupantFirstName.Visible = False
>     CardexOccupantBusinessName.Visible = False
>     CardexOccupantHouseNumber.Visible = False
>     CardexOccupantStreetID.Visible = False
>     CardexOccupantAddlInfo.Visible = False
>     CardexOccupantPOBox.Visible = False
>     CardexOccupantMunicipalityID.Visible = False
>     CardexOccupantStateCode.Visible = False
>     CardexOccupantZipCode.Visible = False
>     CardexOccupantMailingListFlag = False
>     CardexOccupantMailingListFlag.Visible = False
>     CardexOccupantSpecialNeeds.Visible = False
>     CardexOccupantChildren.Visible = False
>     CardexOccupantPets.Visible = False
>     CardexOccupantAnimals.Visible = False
> Else
>     CardexOccupantLastName.Visible = True
>     CardexOccupantFirstName.Visible = True
>     CardexOccupantBusinessName.Visible = True
>     CardexOccupantHouseNumber.Visible = True
>     CardexOccupantStreetID.Visible = True
>     CardexOccupantAddlInfo.Visible = True
>     CardexOccupantPOBox.Visible = True
>     CardexOccupantMunicipalityID.Visible = True
>     CardexOccupantStateCode.Visible = True
>     CardexOccupantZipCode.Visible = True
>     CardexOccupantMailingListFlag.Visible = True
>     CardexOccupantSpecialNeeds.Visible = True
>     CardexOccupantChildren.Visible = True
>     CardexOccupantPets.Visible = True
>     CardexOccupantAnimals.Visible = True
> End If
> If IsNull(CardexWarningReason) Then
>     lblCardexWarning.Visible = False
> Else
>     lblCardexWarning.Visible = True
>     DoCmd.Beep
> End If
> End Sub
> -------------------------
>  
> Private Sub CardexVacantFlag_AfterUpdate()
> If CardexVacantFlag = True Then
>     CardexOccupantLastName = Null
>     CardexOccupantLastName.Visible = False
>     CardexOccupantFirstName = Null
>     CardexOccupantFirstName.Visible = False
>     CardexOccupantBusinessName = Null
>     CardexOccupantBusinessName.Visible = False
>     CardexOccupantHouseNumber = Null
>     CardexOccupantHouseNumber.Visible = False
>     CardexOccupantStreetID = Null
>     CardexOccupantStreetID.Visible = False
>     CardexOccupantAddlInfo = Null
>     CardexOccupantAddlInfo.Visible = False
>     CardexOccupantPOBox = Null
>     CardexOccupantPOBox.Visible = False
>     CardexOccupantMunicipalityID = Null
>     CardexOccupantMunicipalityID.Visible = False
>     CardexOccupantStateCode = Null
>     CardexOccupantStateCode.Visible = False
>     CardexOccupantZipCode = Null
>     CardexOccupantZipCode.Visible = False
>     CardexOccupantMailingListFlag = False
>     CardexOccupantMailingListFlag.Visible = False
>     CardexOccupantSpecialNeeds = Null
>     CardexOccupantSpecialNeeds.Visible = False
>     CardexOccupantChildren = Null
>     CardexOccupantChildren.Visible = False
>     CardexOccupantPets = Null
>     CardexOccupantPets.Visible = False
>     CardexOccupantAnimals = Null
>     CardexOccupantAnimals.Visible = False
> Else
>     CardexOccupantLastName.Visible = True
>     CardexOccupantFirstName.Visible = True
>     CardexOccupantBusinessName.Visible = True
>     CardexOccupantHouseNumber.Visible = True
>     CardexOccupantStreetID.Visible = True
>     CardexOccupantAddlInfo.Visible = True
>     CardexOccupantPOBox.Visible = True
>     CardexOccupantMunicipalityID.Visible = True
>     CardexOccupantStateCode.Visible = True
>     CardexOccupantZipCode.Visible = True
>     CardexOccupantMailingListFlag.Visible = True
>     CardexOccupantSpecialNeeds.Visible = True
>     CardexOccupantChildren.Visible = True
>     CardexOccupantPets.Visible = True
>     CardexOccupantAnimals.Visible = True
> End If
> LastUpdated = Date
> End Sub
> 
>  
> P Please consider the environment before printing this e-mail 
>  



More information about the AccessD mailing list