473,396 Members | 1,743 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Contingent formatting

Problem:

When moving between records, I need to control which combo/text boxes
are displayed on the current form, dependent upon data in the current
record.

More:

I building my first access database.

Record entry is by a single form, and the form contains many cases of
contingent combo boxes, text boxes, etc.

When building the form, I was testing only the form by itself for a
single record, not moving between records. Everything works fine so
long as you do not move between records.

However, when I move between records, the formatting (ie. which
combo/text boxes are visible/enabled) remains as it was on the most
recent manually entered record.

A simple way to address this would be to have an 'OnChangeRecord' type
event which detects presses on the MS Access default record controls
which appear at the bottom left of the screen. Is this possible? If so,
how?

For my form formatting, I have used the _Change event for combo boxes.
Where should this formatting go, and where does it need to be to update
correctly whenever a user moves between records?

I have experimented with the Form_AfterUpdate event without success.
Any help greatly appreciated.

Dec 21 '05 #1
12 2330
The Current event of the form fires whenever the user moves record.

The Change event of a combo fires for every keystroke, so use its
AfterUpdate event to respond to a change in value.

If you have lots of controls that need to be hidden/shown, you probably need
a different data structure, where some of the attributes you are saving
become values in a related table rather than fields of the one big table.

You cannot conditionally hide columns if your form is in Continuous or
Datasheet view.

--
Allen Browne - Microsoft MVP. Perth, Western Australia.
Tips for Access users - http://allenbrowne.com/tips.html
Reply to group, rather than allenbrowne at mvps dot org.

"dmieluk" <dm*****@exemail.com.au> wrote in message
news:11**********************@f14g2000cwb.googlegr oups.com...
Problem:

When moving between records, I need to control which combo/text boxes
are displayed on the current form, dependent upon data in the current
record.

More:

I building my first access database.

Record entry is by a single form, and the form contains many cases of
contingent combo boxes, text boxes, etc.

When building the form, I was testing only the form by itself for a
single record, not moving between records. Everything works fine so
long as you do not move between records.

However, when I move between records, the formatting (ie. which
combo/text boxes are visible/enabled) remains as it was on the most
recent manually entered record.

A simple way to address this would be to have an 'OnChangeRecord' type
event which detects presses on the MS Access default record controls
which appear at the bottom left of the screen. Is this possible? If so,
how?

For my form formatting, I have used the _Change event for combo boxes.
Where should this formatting go, and where does it need to be to update
correctly whenever a user moves between records?

I have experimented with the Form_AfterUpdate event without success.
Any help greatly appreciated.

Dec 21 '05 #2
Thank you for your quick reply.
The Current event of the form fires whenever the user moves record.


In form view, Access provides default record selection buttons. Is the
Current event supposed to fire when the user changes record using these
buttons? I added this code to my form:

Private Sub Form_Current()

Beep

End Sub

I do not hear the beep when I change records using the provided
buttons.

By contrast, I do hear the beep when I add the beep command to one of
my existing combo box Change events (when I change that combo box).

Dec 21 '05 #3
Yes: Form_Current fires with the built-in nav. buttons.

Replace
beep
with
Debug.Print "Changed record at " & Now()

Open the Immediate Window (Ctrl+G) and watch the output.

--
Allen Browne - Microsoft MVP. Perth, Western Australia.
Tips for Access users - http://allenbrowne.com/tips.html
Reply to group, rather than allenbrowne at mvps dot org.

"dmieluk" <dm*****@exemail.com.au> wrote in message
news:11*********************@o13g2000cwo.googlegro ups.com...
Thank you for your quick reply.
The Current event of the form fires whenever the user moves record.


In form view, Access provides default record selection buttons. Is the
Current event supposed to fire when the user changes record using these
buttons? I added this code to my form:

Private Sub Form_Current()

Beep

End Sub

I do not hear the beep when I change records using the provided
buttons.

By contrast, I do hear the beep when I add the beep command to one of
my existing combo box Change events (when I change that combo box).

Dec 21 '05 #4
Hmmm.

I'll be as explicit as I can because this is starting to get strange.

I altered the code as said, and opened the Immediate window.

I saved the code, opened the form and went to form view.

I used the default Nav buttons to move between records, and also edited
a few records, and created a new record.

There was no entry in the immediate window.

Then, I added the Debug code(Debug.Print "Changed record at " & Now())
into one of my combo box change events. I returned to form view, used
the combo box, and the immediate window subsequently had an entry
(Changed record at 21/12/2005 2:44:42 PM).

I am using Windows XP with MS Access 2000.

The form code is exactly:

Private Sub Form_Current()

Debug.Print "Changed record at " & Now()

End Sub

and this procedure is in the same place where all the form events are
placed by default (Indeed, the event was created automatically using
the drop down menus).

Perplexed.

Dec 21 '05 #5
Allen already answered most everything, and so here are my 2cents as
well. :)
To show or hide specific controls based on the record you are showing I
usually do it this way.
In the properties for the controls you will see one called Tag. For
all the controls you want to disable, put in a word that signifies
something to do with why you are disabling these controls - for this
example, we'll use the word Employed. I don't know what you are
looking for that will signal to the form to hide records, but just for
the sake of explanation, lets say you have a field called Employed and
it's either true or false.
Now in your foms OnCurrent event
dim ctlDisable as control
for each ctlDisable in me.controls
If ctlDisable.tag="Employed" then ctlDisabled.enabled=me!Employed
next
Anyway I hope that helps you

Dec 21 '05 #6
Presumably this is a bound form, because the built-in nav buttons would not
do anything in an unbound form.

If Form_Current is not firing, the database is partially corrupt. Follow
this sequence until you start seeing the debug.print working.

1. Uncheck the boxes under:
Tools | Options | General | Name AutoCorrect
Explanation of why:
http://allenbrowne.com/bug-03.html

2. Compact the database to get rid of this junk:
Tools | Database Utilities | Compact

3. Close Access. Make a backup copy of the file. Decompile the database by
entering something like this at the command prompt while Access is not
running. It is all one line, and include the quotes:
"c:\Program Files\Microsoft office\office\msaccess.exe" /decompile
"c:\MyPath\MyDatabase.mdb"

4. Open Access, and compact again.

5. Open a code window.
Choose References from the Tools menu.
Uncheck any references you do not need.
For a list of the ones you typically need in your version of Access, see:
http://allenbrowne.com/ser-38.html

6. Still in the code window, choose Compile from the Debug menu.
Fix any errors, and repeat until it compiles okay.

At this point, you should have a database where the name-autocorrect errors
are gone, the indexes are repaired, inconsistencies between the text- and
compiled-versions of the code are fixed, and reference ambiguities are
resolved.

If it is still a problem, the next step would be to get Access to rebuild
the database for you. Follow the steps for the first symptom in this
article:
Recovering from Corruption
at:
http://allenbrowne.com/ser-47.html

--
Allen Browne - Microsoft MVP. Perth, Western Australia.
Tips for Access users - http://allenbrowne.com/tips.html
Reply to group, rather than allenbrowne at mvps dot org.

"dmieluk" <dm*****@exemail.com.au> wrote in message
news:11**********************@z14g2000cwz.googlegr oups.com...
Hmmm.

I'll be as explicit as I can because this is starting to get strange.

I altered the code as said, and opened the Immediate window.

I saved the code, opened the form and went to form view.

I used the default Nav buttons to move between records, and also edited
a few records, and created a new record.

There was no entry in the immediate window.

Then, I added the Debug code(Debug.Print "Changed record at " & Now())
into one of my combo box change events. I returned to form view, used
the combo box, and the immediate window subsequently had an entry
(Changed record at 21/12/2005 2:44:42 PM).

I am using Windows XP with MS Access 2000.

The form code is exactly:

Private Sub Form_Current()

Debug.Print "Changed record at " & Now()

End Sub

and this procedure is in the same place where all the form events are
placed by default (Indeed, the event was created automatically using
the drop down menus).

Perplexed.

Dec 21 '05 #7
Thanks for your help Allen.

I follow through this carefully and see if I can get it going.

Dec 21 '05 #8
On 20 Dec 2005 19:48:20 -0800, "dmieluk" <dm*****@exemail.com.au>
wrote:

This could be a case of "event procedure not connected to event".
Proceed as follows:
Bring form in design view
Show form-level properties
Select Events, and click the ... button next to the Current event.
Observe that the code window opens, with your Beep code or Debug.Print
code.
Close all and test again.
If it works now, then the above has reconnected the event procedure to
the event. No corruption was ever there.

-Tom.

Hmmm.

I'll be as explicit as I can because this is starting to get strange.

I altered the code as said, and opened the Immediate window.

I saved the code, opened the form and went to form view.

I used the default Nav buttons to move between records, and also edited
a few records, and created a new record.

There was no entry in the immediate window.

Then, I added the Debug code(Debug.Print "Changed record at " & Now())
into one of my combo box change events. I returned to form view, used
the combo box, and the immediate window subsequently had an entry
(Changed record at 21/12/2005 2:44:42 PM).

I am using Windows XP with MS Access 2000.

The form code is exactly:

Private Sub Form_Current()

Debug.Print "Changed record at " & Now()

End Sub

and this procedure is in the same place where all the form events are
placed by default (Indeed, the event was created automatically using
the drop down menus).

Perplexed.


Dec 21 '05 #9
On 20 Dec 2005 19:48:20 -0800, "dmieluk" <dm*****@exemail.com.au> wrote:

and this procedure is in the same place where all the form events are
placed by default (Indeed, the event was created automatically using
the drop down menus).

Perplexed.


Open the Property Sheet for the form and click the Event tab.
In the text box next to On Current make sure that it has [Event Procedure] entered.

Code against each event will not fire unless this property is set. It sounds like your form may not have this property
set.

If you create a procedure in the VBE window directly (by using the drop down menus), this property is not set
automatically and you must enter [Event Procedure] in the property sheet against the related event before the code will
fire.

To set the property automatically you must initiate the code creation from the property sheet.
In the property sheet, click in the Event you wish to create. An elipse? button (...) will appear to the extreme left of
the property. Click this button and select Event Procedure. The VBE window will open with procedure header and footer
created, and [Event Procedure] will be entered in the property sheet automatically.
Wayne Gillespie
Gosford NSW Australia
Dec 21 '05 #10
On Wed, 21 Dec 2005 11:57:55 +0800, "Allen Browne" <Al*********@SeeSig.Invalid> wrote:

I would suggest that this more likely due to the [Event Procedure] not being set in the form's properties, rather than
corruption. The OP indicated that the Form_Current procedure was created directly in the VBE, which will not
automatically set the property.
Presumably this is a bound form, because the built-in nav buttons would not
do anything in an unbound form.

If Form_Current is not firing, the database is partially corrupt. Follow
this sequence until you start seeing the debug.print working.

1. Uncheck the boxes under:
Tools | Options | General | Name AutoCorrect
Explanation of why:
http://allenbrowne.com/bug-03.html

2. Compact the database to get rid of this junk:
Tools | Database Utilities | Compact

3. Close Access. Make a backup copy of the file. Decompile the database by
entering something like this at the command prompt while Access is not
running. It is all one line, and include the quotes:
"c:\Program Files\Microsoft office\office\msaccess.exe" /decompile
"c:\MyPath\MyDatabase.mdb"

4. Open Access, and compact again.

5. Open a code window.
Choose References from the Tools menu.
Uncheck any references you do not need.
For a list of the ones you typically need in your version of Access, see:
http://allenbrowne.com/ser-38.html

6. Still in the code window, choose Compile from the Debug menu.
Fix any errors, and repeat until it compiles okay.

At this point, you should have a database where the name-autocorrect errors
are gone, the indexes are repaired, inconsistencies between the text- and
compiled-versions of the code are fixed, and reference ambiguities are
resolved.

If it is still a problem, the next step would be to get Access to rebuild
the database for you. Follow the steps for the first symptom in this
article:
Recovering from Corruption
at:
http://allenbrowne.com/ser-47.html


Wayne Gillespie
Gosford NSW Australia
Dec 21 '05 #11
Good thought. Thanks Wayne and Tom. Very likely.

--
Allen Browne - Microsoft MVP. Perth, Western Australia.
Tips for Access users - http://allenbrowne.com/tips.html
Reply to group, rather than allenbrowne at mvps dot org.

"Wayne Gillespie" <be*****@NOhotmailSPAM.com.au> wrote in message
news:1f********************************@4ax.com...
On Wed, 21 Dec 2005 11:57:55 +0800, "Allen Browne"
<Al*********@SeeSig.Invalid> wrote:

I would suggest that this more likely due to the [Event Procedure] not
being set in the form's properties, rather than
corruption. The OP indicated that the Form_Current procedure was created
directly in the VBE, which will not
automatically set the property.

Dec 21 '05 #12
Ok, thank you very much guys, for all your help.

I did not have the event procedure option selected.

I have made this alteration and it has solved the problem.

Kudos to the support gurus who help out at this forum.

Dec 21 '05 #13

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Jouke Langhout | last post by:
Hello all! For quite some time now, I've got the following problem: Access won't close properly when a user closes the application. An ACCESS process stays active and that process can only be...
2
by: Colleyville Alan | last post by:
I am using Access and have embedded the ActiveX control Formula One that came with Office 2000. (ver 3.04). I have created and formatted a spreadsheet and now I want to copy the info with...
4
by: DBQueen | last post by:
I have a subform which is in Continuous Forms view. I have added a button to the bottom of the page to move to the next record using the button wizard (result: DoCmd.GoToRecord , , acNext). I...
4
by: Bradley | last post by:
I have an A2000 database in which I have a continuous form with a tick box. There is also a text box with a conditional format that is based on the expression , if it's true then change the...
4
by: hope | last post by:
Hi, How can I format a string field using Data Formatting Expression property in datagrid? For example: format last name from BROWN to Brown. Thanks
7
by: L. Scott M. | last post by:
Have a quick simple question: dim x as string x = "1234567890" ------------------------------------------------------- VB 6 dim y as string
8
by: gopal | last post by:
Hi I am trying to write to log file but the formatting of string is not properly aligned in log file result The results looks some thing like this OK move.xml Successful OK ...
8
by: Typehigh | last post by:
I have many text fields with conditional formatting applied, specifically when the condition is "Field Has Focus". Without any events associated with the fields the conditional formatting works...
6
by: BUmed | last post by:
Hi all I’m trying to figure this out. But help is needed. I have a combo box called fcmFLAG with 5 options (problem, hold off, call, withdrew and ineligible). What I would like to do is have the...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.