473,320 Members | 1,978 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,320 software developers and data experts.

Repaint onCurrent not working

I am going to open a new discussion that refers back to this pervious one.

https://bytes.com/topic/access/answe...lp#post3805999

I have code that runs for fields to be visible and invisible in my form. It is all working except when I move to a new record. The "repaint" is not working in the OnCurrent part of the form.

I have tried moving it around, but does not seem to be working. Any help would be appreciated.

Thanks
Attached Files
File Type: zip VisibleField_Working - byte.zip (90.3 KB, 68 views)
Sep 9 '16 #1

✓ answered by jforbes

I would take a slightly different approach. I would Enable and Disable your fields instead of Hiding or Showing them as it's usually easier on your users.

I would also move all the enable/disable code into one function where everything is Disabled to start with and then Enabled as needed. It will be easier to maintain and troubleshoot. Make sure you set all your fields Visible property to True. Then use this code or something similar:
Expand|Select|Wrap|Line Numbers
  1. Private Sub Form_Current()
  2.     Call enableDisable
  3. End Sub
  4. Private Sub opgHowLate_AfterUpdate()
  5.     Call enableDisable
  6. End Sub
  7. Private Sub opgVisitType_AfterUpdate()
  8.     Call enableDisable
  9. End Sub
  10.  
  11. Private Sub enableDisable()
  12.  
  13.     Me.ckbFastTrackPaper.Enabled = False
  14.     Me.ckbEvalShortTreat.Enabled = False
  15.     Me.ckbEvalOnly.Enabled = False
  16.     Me.ckbReschedule.Enabled = False
  17.     Me.opgRescheduleWhen.Enabled = False
  18.     Me.opgRescheduleProvider.Enabled = False
  19.  
  20.     Select Case Me.opgVisitType
  21.         Case 1
  22.             Select Case Me.opgHowLate
  23.                 Case 1
  24.                     Me.ckbFastTrackPaper.Enabled = True
  25.  
  26.                 Case 2
  27.                     Me.ckbEvalShortTreat.Enabled = True
  28.                     Me.ckbEvalOnly.Enabled = True
  29.                     Me.ckbReschedule.Enabled = True
  30.                     Me.opgRescheduleWhen.Enabled = True
  31.                     Me.opgRescheduleProvider.Enabled = True
  32.  
  33.                 Case 3
  34.                     Me.ckbEvalOnly.Enabled = True
  35.                     Me.ckbReschedule.Enabled = True
  36.                     Me.opgRescheduleWhen.Enabled = True
  37.                     Me.opgRescheduleProvider.Enabled = True
  38.             End Select
  39.         Case 2
  40.             Me.ckbShorterVisit.Enabled = True
  41.             Select Case Me.opgHowLate
  42.                 Case 2 Or 3
  43.                     Me.ckbReschedule.Enabled = True
  44.                     Me.opgRescheduleWhen.Enabled = True
  45.                     Me.opgRescheduleProvider.Enabled = True
  46.  
  47.             End Select
  48.     End Select
  49.  
  50. End Sub
Hopefully I got everything to enable and disable as needed, you may need to tweak the code if a control doesn't turn on when you expect it to.

5 1306
jforbes
1,107 Expert 1GB
I would take a slightly different approach. I would Enable and Disable your fields instead of Hiding or Showing them as it's usually easier on your users.

I would also move all the enable/disable code into one function where everything is Disabled to start with and then Enabled as needed. It will be easier to maintain and troubleshoot. Make sure you set all your fields Visible property to True. Then use this code or something similar:
Expand|Select|Wrap|Line Numbers
  1. Private Sub Form_Current()
  2.     Call enableDisable
  3. End Sub
  4. Private Sub opgHowLate_AfterUpdate()
  5.     Call enableDisable
  6. End Sub
  7. Private Sub opgVisitType_AfterUpdate()
  8.     Call enableDisable
  9. End Sub
  10.  
  11. Private Sub enableDisable()
  12.  
  13.     Me.ckbFastTrackPaper.Enabled = False
  14.     Me.ckbEvalShortTreat.Enabled = False
  15.     Me.ckbEvalOnly.Enabled = False
  16.     Me.ckbReschedule.Enabled = False
  17.     Me.opgRescheduleWhen.Enabled = False
  18.     Me.opgRescheduleProvider.Enabled = False
  19.  
  20.     Select Case Me.opgVisitType
  21.         Case 1
  22.             Select Case Me.opgHowLate
  23.                 Case 1
  24.                     Me.ckbFastTrackPaper.Enabled = True
  25.  
  26.                 Case 2
  27.                     Me.ckbEvalShortTreat.Enabled = True
  28.                     Me.ckbEvalOnly.Enabled = True
  29.                     Me.ckbReschedule.Enabled = True
  30.                     Me.opgRescheduleWhen.Enabled = True
  31.                     Me.opgRescheduleProvider.Enabled = True
  32.  
  33.                 Case 3
  34.                     Me.ckbEvalOnly.Enabled = True
  35.                     Me.ckbReschedule.Enabled = True
  36.                     Me.opgRescheduleWhen.Enabled = True
  37.                     Me.opgRescheduleProvider.Enabled = True
  38.             End Select
  39.         Case 2
  40.             Me.ckbShorterVisit.Enabled = True
  41.             Select Case Me.opgHowLate
  42.                 Case 2 Or 3
  43.                     Me.ckbReschedule.Enabled = True
  44.                     Me.opgRescheduleWhen.Enabled = True
  45.                     Me.opgRescheduleProvider.Enabled = True
  46.  
  47.             End Select
  48.     End Select
  49.  
  50. End Sub
Hopefully I got everything to enable and disable as needed, you may need to tweak the code if a control doesn't turn on when you expect it to.
Sep 9 '16 #2
I just had a conversation with someone about considering doing it with Enable/Disable. So Thank you!


Thanks also for the awesome examples and where to do things. I feel like I learned a great deal from you! It feels good!
Sep 9 '16 #3
TheSmileyCoder
2,322 Expert Mod 2GB
Sometimes I find it easier to set the enabled of a single control at a time, instead of as a group with statements like:
Expand|Select|Wrap|Line Numbers
  1. Me.ckbFastTrackPaper.Enabled=(Me.opgVisitType=1 and Me.opgHowLate=1)
  2.  
  3. Me.ckbEvalShortTreat.Enabled=(Me.opgVisitType=1 and Me.opgHowLate=2)
I personally find the logic easier to follow, than the nested Case statements, but that might just be a matter of preference.
Sep 12 '16 #4
Thanks!

It does make it easier to understand. I did not know you could do it that way.

I appreciate you showing me this.
Sep 12 '16 #5
jforbes
1,107 Expert 1GB
That's a really good point!

It's often preferable to list the control only once. Another thing to consider when using this method is to load most or all values on the Form that are being referred to into variables. That way they are only being accesses once and the code will get even easier to read. To build on what Smiley has provided:
Expand|Select|Wrap|Line Numbers
  1. Private Sub enableDisable
  2.  
  3.     Dim bEvalVisit As Boolean
  4.     Dim iHowLate as Integer
  5.  
  6.     bEvalVisit = (Me.opgVisitType=1)
  7.     iHowLate = Me.opgHowLate
  8.  
  9.     Me.ckbFastTrackPaper.Enabled=(bEvalVisit And iHowLate=1)
  10.     Me.ckbEvalShortTreat.Enabled=(bEvalVisit And iHowLate=2)
  11. ...
Sep 13 '16 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: Martin | last post by:
Hi All, I am a relative newbie to Java / Applets, but am despirately after some help ! I have got the following code, which is basically a listing with button items along the sides, allowing...
2
by: Joe A | last post by:
I'm using Access 2002 on Windows XP PC, 500 megs ram, Front end/back end app. I have a simple form that draws a thermometer to indicate progress of code that is running. The thermometer form...
5
by: Brian | last post by:
Hello all.. Am working on an Air Hockey game... have an table loaded into a picture box. The borders of the table are slightly slanted. Am using hit testing lines with GDI+ to manipulate the...
7
by: Paul | last post by:
I have a VB.NET form with a DataGrid. When I toggle to Excel (for example) and then back to my application the repaint of the DataGrid is really slow. You can see the repainting happening. When...
2
by: Rational Repairs | last post by:
I have run into a sudden problem and thought I'd see if anyone else has ran into this. Out of nowhere (sort-of) I am not able to access the OnCurrent event on a subform. I, of course, can write...
5
by: TomK | last post by:
I would like to use the oncurrent event of a subform. The subform class seems to offer onEnter and onExit only, so I tried up to set the event handling routine programatically. It works fine with a...
4
by: drexlin | last post by:
Hi, I hope this is the correct place to post questions about visual c++ 6.0. If not, sorry. Anyway, the program I am working on takes messages from another computer and prints them on the screen....
0
by: milkay | last post by:
<I have code that uses 2 images> the program creates a window and then when u press play, it removes all components in the container. then, i add a NewPanel object. i add mouse listeners and all...
3
by: Tetelestai | last post by:
I have a command button on a form that should be visible or not visible depending on a value in the current record and the current users user level. The code below is working as in the immediate...
4
Seth Schrock
by: Seth Schrock | last post by:
I have a form that has a combo box in the header that I use to navigate through the records in the form. This combo box uses the DoCmd.SearchForRecord method to go to the selected record. If I...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

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.