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

Refreshing Controls

SixHat
7
I unfortunately am having the same issue... I've been researching it and have found many similar cases... but so far this seems to be the closest.

For me I am not new to Access development or VBA but I've been stuck on this one for hours and am reaching out. I can however provide more background as to why my situation is running into this problem.

I just recently did a SQL Server Migration and am now troubleshooting the issues that have sprung up with the new SQL back end. This is the last one that I can not figure out:

I have a split form with a check box control... currently the form is not updatable because the form is bound to a view through a DSN-Less connection.

Here is the ringer: I have a check all check box at the top of the form... and even though the bound form is not updatable I update the records like so:

Expand|Select|Wrap|Line Numbers
  1.     Dim rsSelect As DAO.Recordset
  2.     Dim rsUpdate As DAO.Recordset
  3.     Dim SQL As String
  4.     Dim CurrDb As Database
  5.     Dim currFilter As String
  6.  
  7.  
  8.    On Error GoTo chkSelect_Click_Error
  9.    ' Capture current filter
  10.     If Me.FilterOn Then currFilter = Me.Filter
  11.     Set rsSelect = Me.RecordsetClone
  12.  
  13.     Set CurrDb = CurrentDb
  14.  
  15.      rsSelect.MoveFirst
  16.     Do While Not rsSelect.EOF
  17.          SQL = "SELECT * FROM tblTimesheet WHERE [TimesheetID] = " & rsSelect("TimesheetID")
  18.         Set rsUpdate = CurrDb.OpenRecordset(SQL, dbOpenDynaset, dbSeeChanges)
  19.         If Not rsUpdate.EOF Then
  20.             If Me.chkSelect Then
  21.                 With rsUpdate
  22.                     .Edit
  23.                     rsUpdate("TimesheetSelect") = True
  24.                     .Update
  25.                 End With
  26.             Else
  27.                  With rsUpdate
  28.                     .Edit
  29.                     rsUpdate("TimesheetSelect") = False
  30.                     .Update
  31.                 End With
  32.             End If
  33.         End If
  34.         rsSelect.MoveNext
  35.      Loop
  36.     rsUpdate.Close
  37.     rsSelect.Close
  38.     Me.Requery
  39.     If currFilter > "" Then
  40.         Me.Filter = currFilter
  41.         Me.FilterOn = True
  42.     End If
  43.     If Me.chkSelect Then
  44.         Me.lblSelect.Caption = "Select None"
  45.     Else
  46.         Me.lblSelect.Caption = "Select All"
  47.     End If
  48.  
  49.    On Error GoTo 0
  50.    Exit Sub
  51.  
  52. chkSelect_Click_Error:
  53.  
  54.     MsgBox "Error " & Err.Number & " (" & Err.Description & ") in procedure chkSelect_Click of VBA Document Form_frmTimesheetSummary"
  55.  
Here is the kicker... I replicated this same code for when a user click's an individual checkbox... and this formely worked with the Access back end... but now I can't get the individual checkbox to update but the check all/ none code still works!

Here is the code for the individual checkbox:
Expand|Select|Wrap|Line Numbers
  1.     Dim rsUpdate As DAO.Recordset
  2.     Dim SQL As String
  3.     Dim CurrDb As Database
  4.     Dim currFilter As String
  5.  
  6.    ' Capture current filter
  7.     If Me.FilterOn Then currFilter = Me.Filter
  8.  
  9.     Set CurrDb = CurrentDb
  10.      SQL = "SELECT * FROM tblTimesheet WHERE [TimesheetID] = " & Me.TimesheetID
  11.     Set rsUpdate = CurrDb.OpenRecordset(SQL, dbOpenDynaset, dbSeeChanges)
  12.     If Not rsUpdate.EOF Then
  13.         If Me.TimesheetSelect Then
  14.             With rsUpdate
  15.                 .Edit
  16.                 rsUpdate("TimesheetSelect") = False
  17.                 .Update
  18.             End With
  19.         Else
  20.              With rsUpdate
  21.                 .Edit
  22.                 rsUpdate("TimesheetSelect") = True
  23.                 .Update
  24.             End With
  25.         End If
  26.     End If
  27.  
  28.  
  29.     rsUpdate.Close
  30.     Me.Form.Requery
  31.     'Me.Repaint
  32.     Me.Refresh
  33.     If currFilter > "" Then
  34.         Me.Filter = currFilter
  35.         Me.FilterOn = True
  36.     End If
  37.  
I run this code on the Checkboxes MouseDown Event. I hope this makes sense... so in short my first bit of code which checks or unchecks all of the checkboxes works... but my second bit which a user would use to check each one individually does not work. But note it is updating the back end... If I close and reopen the form like the SO then it shows the updated records checked... but I can not get it to update... AND I've tried what worked for the SO i.e. Repaint, and Refresh... although I really feel all that should be needed is a Requery.

Any help in this would be greatly appreciated!
Dec 19 '15 #1

✓ answered by zmbd

+ Well, I'm at a bit of a loss here TBH so the following are just some things that occur to me in no particular order (other than this first one... :) )

+ your code to the on_click event of the control not the mouse_down event. May not make a difference. If the record is showing as edited in the form this may be causing some disconnect between the form record-set the backend. The record should be in a saved state. We may need to do this in the before_update event and set the cancel to true, me.undo, and then requery once your backend is edited.

+ Split forms have some very unusual behaviors.
To test this I would create a new, non-split, form based on your record source and try the same codes etc... if this behavior reoccurs then this may be a quirk in the connection. It could be the underlying functioning of the split form that is running like a timer event or other code as suggested by Nico5038 in the old thread that is causing the issue.

+ A hypothesis: Because the record-source is being opened as "read-only" Access may be too smart for its own good and assuming that there can be no changes to the record-set; thus, when one attempts to requery the program assumes that there can be no changes so it simply bypasses the form update.

+ There appears to occasionally be a disconnect between the SQL-Server and Access when it comes to updating. One article I've just perused suggested that all of the tables on the SQL-Sever side have a timestamp field as Access will use this field when pulling data.

Because you are altering the underlying record source directly, it may be that the timestamp isn't being properly updated in the backend until after the form is closed.

It would be best to find a way to make the record directly editable.

+ Check the default refresh time.
Accss2013>Ribbon>File>Options>Client Settings>Advanced
You might try reducing the ODBC refresh (manual requery should over-ride this setting)

++ On a side note:

Seth (IIRC) had an issue with the Y/N fields when they contained a null value. This is indeed a known issue between Access and SQL-Server that I don't believe MS has addressed. Double check that you have no null values in this field and set the field to not allow nulls and to have a default value.
(this article reminded me of that issue:
Five Common Pitfalls When Upgrading Access to SQL Server. It's an old article; however, I see the same comments over and over again in the other blogs/articles regarding the migration to SQL-Server.

No Worries about the posting in the old thread... Bytes has a different "feel" than many of the other sites. Especially in this case, the old solution found in the prior thread didn't work for you; thus, although related, this is fundamentally a new question - sort of like cousins are related, yet different.

12 1754
zmbd
5,501 Expert Mod 4TB
Split this from:
Refreshing Checkbox control after programmatic update

SixHat - Please do not hijack threads, start a new thread with a link to the old if needed for context.

I have a split form
A creation from the evil mind of a sadistic program engineer.

These forms have no end of troubles when doing anything beyond the basic display and edit of bound record-sets. Bytes.com is full of threads regarding this torture device.
...SQL Server Migration and am now troubleshooting the issues...but now I can't get the individual checkbox to update but the check all/ none code still works!
+Me.Form.Requery
Curious about this construct, it can cause some issues.

+ You haven't explicitly stated this; however, inferring from the first portion of your post try changing all of your Me.Requery entries to:
Expand|Select|Wrap|Line Numbers
  1.     With Me
  2.         .RecordSource = Me.RecordSource
  3.         .Refresh
  4.         .Repaint
  5.     End With
(this is a cut-n-paste from a working front-end so it should work for you too)

The repaint shouldn't be needed; however, never hurts to force the re-draw of the form.

You most likely will loose the current record pointer when you reset the record source... see what happens and if you do lose the position then use a form level variable to store the current record's primary key and then use findfirst to find that record against the primary key (this is one reason why I always use a single field primary key :) ) then the bookmark to move the form's bookmark to that record.
Dec 20 '15 #2
SixHat
7
@Zmbd... Thank you for the reply... and sorry for the "Hijacking".

I am new to Bytes, and am used to other forums that would have considered this question a duplicate because it is pretty much the same situation as the initial thread I posted the question on... except the resolution that worked for that OP didn't work for me.

I copied and pasted in yours as well and unfortunately it still didn't repaint... unless I close and re-open the form. It's the craziest thing!
Dec 20 '15 #3
zmbd
5,501 Expert Mod 4TB
+ Well, I'm at a bit of a loss here TBH so the following are just some things that occur to me in no particular order (other than this first one... :) )

+ your code to the on_click event of the control not the mouse_down event. May not make a difference. If the record is showing as edited in the form this may be causing some disconnect between the form record-set the backend. The record should be in a saved state. We may need to do this in the before_update event and set the cancel to true, me.undo, and then requery once your backend is edited.

+ Split forms have some very unusual behaviors.
To test this I would create a new, non-split, form based on your record source and try the same codes etc... if this behavior reoccurs then this may be a quirk in the connection. It could be the underlying functioning of the split form that is running like a timer event or other code as suggested by Nico5038 in the old thread that is causing the issue.

+ A hypothesis: Because the record-source is being opened as "read-only" Access may be too smart for its own good and assuming that there can be no changes to the record-set; thus, when one attempts to requery the program assumes that there can be no changes so it simply bypasses the form update.

+ There appears to occasionally be a disconnect between the SQL-Server and Access when it comes to updating. One article I've just perused suggested that all of the tables on the SQL-Sever side have a timestamp field as Access will use this field when pulling data.

Because you are altering the underlying record source directly, it may be that the timestamp isn't being properly updated in the backend until after the form is closed.

It would be best to find a way to make the record directly editable.

+ Check the default refresh time.
Accss2013>Ribbon>File>Options>Client Settings>Advanced
You might try reducing the ODBC refresh (manual requery should over-ride this setting)

++ On a side note:

Seth (IIRC) had an issue with the Y/N fields when they contained a null value. This is indeed a known issue between Access and SQL-Server that I don't believe MS has addressed. Double check that you have no null values in this field and set the field to not allow nulls and to have a default value.
(this article reminded me of that issue:
Five Common Pitfalls When Upgrading Access to SQL Server. It's an old article; however, I see the same comments over and over again in the other blogs/articles regarding the migration to SQL-Server.

No Worries about the posting in the old thread... Bytes has a different "feel" than many of the other sites. Especially in this case, the old solution found in the prior thread didn't work for you; thus, although related, this is fundamentally a new question - sort of like cousins are related, yet different.
Dec 20 '15 #4
jforbes
1,107 Expert 1GB
zmbd touched on it... but I would make sure that every Table in SQL has a timestamp field. This is the type of thing that can happen without it.

To rule out the Split Form possibility, when does your code above run? When a Command Button is clicked or in the Checkbox AfterUpdate Event? If it is on the Checkbox, does it error the same from the Dataview portion of the Form and the Single Form portion of the Form?

I'm also curious how you are Binding your Form. I don't see why the Form wouldn't be updatable, unless you are binding to a complex query or you are not supplying a Key when linking to the Table.
Dec 20 '15 #5
SixHat
7
@Zmbd & @jforbes I used SSMA for the initial migration which beautifully adds the timestamp field... although I have found in the past sometimes tables get missed but I've double checked and its there.

I used the click event for the "Check All" checkbox as it was unbound and fully clickable... but the "Check Individual" check box is as stated bound to an non-updatable view... since the record source is not updatable then the checkboxes Click_Event never fires... thus the switch to the Mouse_Down event.

Yes it is a complex query that holds aggregate values and joined on at least 5 tables. And yes the table does have a primary key. The craziest part about this is that the table is being updated... I've confirmed this several times by looking directly at the table after manually clicking a checkbox... the form just refuses to reflect this update.

Zmbd's hypothesis makes sense... but again the confusing part is that the check all logic works... but the check individual logic does not work?

I will try recreating the form without the split and let you know.
Dec 21 '15 #6
zmbd
5,501 Expert Mod 4TB
Lets force the engine to complete any pending tasks that might be the result of your mouse method or the split form...
Expand|Select|Wrap|Line Numbers
  1.     DBEngine.Idle dbRefreshCache 
  2.     With Me
  3.          .RecordSource = Me.RecordSource
  4.          .Refresh
  5.          .Repaint
  6.      End With
Dec 21 '15 #7
SixHat
7
Thanks to all who posted... the answer turned out to be what @Zmbd stated from the outset about split forms: "A creation from the evil mind of a sadistic program engineer"

When I redesigned the form in a Parent/ Subform design it all worked again.
Dec 21 '15 #8
zmbd
5,501 Expert Mod 4TB
I'm glad that solved the issue... this was a real head=scratcher.

If you wouldn't mind, could you try the last bit of code with the DBEngine.Idle dbRefreshCache would be nice to know if this helped with the split form and would be a better solution to your original question if it does allow the form to update the way it should.
Dec 21 '15 #9
jforbes
1,107 Expert 1GB
If you haven't put all your toys away yet, there is something you can attempt to address your problem on your Split Form.

My understanding of Split Forms has been largely shaped by this article: https://bytes.com/topic/access/answe...-a#post3778277 You can read it if you want, but the basic idea is that when a Split Form is created and displayed, there are two instances of the Form created and placed in a single Form Container. One is the Datasheet View and the other is the Form View. Each has their own copy of controls, variables and code. When one of the Forms is updated, Access updates the other for you, with Magic. Unfortuantly, this magic isn't foolproof, and I would agree with zmdb that there might be some sadistic and evil goings on here.

So, if you are up for it, there is a trick that might work for you. The trick is to include a check to see what the current view happens to be (Form or Datasheet) and if it is a Datasheet then hop out of the current running procedure and call the procedure on a Form in the Forms Collection. This way it will force the Form View version of the Form's code to be executed.

To do this, the first thing to do is move the code in the MouseDown event to it's on Subroutine and add the Datasheet/Form Check, kind of like this:
Expand|Select|Wrap|Line Numbers
  1. Public Sub updateTimeSheet()
  2.  
  3.     Dim rsUpdate As DAO.Recordset
  4.     Dim SQL As String
  5.     Dim CurrDb As Database
  6.     Dim currFilter As String
  7.  
  8.  
  9.     If Me.CurrentView = 2 Then
  10.         If isLoaded(Me.Name) Then Forms (Me.Name).updateTimeSheet
  11.     Else
  12.         ' Capture current filter
  13.         If Me.FilterOn Then currFilter = Me.Filter
  14.  ... 
  15.         Me.Refresh
  16.         If currFilter > "" Then
  17.             Me.Filter = currFilter
  18.             Me.FilterOn = True
  19.         End If
  20.     End If
  21.  
You'll also need this function. Well you don't need it, but it's handy. Put it in a module somewhere:
Expand|Select|Wrap|Line Numbers
  1. Function isLoaded(ByRef sFormName As String) As Boolean
  2.     ' Determines if a Form is loaded
  3.     Dim i As Integer
  4.  
  5.     isLoaded = False
  6.     For i = 0 To Forms.Count - 1
  7.         If Forms(i).FormName = sFormName Then
  8.             isLoaded = True
  9.             Exit Function
  10.         End If
  11.     Next
  12. End Function
You'll then need to go back to the Checkbox and have it call the new Subroutine. One other thing I would change while you are at this is to use the AfterUpdate Event instead of the MouseDown Event. It probably won't make a difference, but it might.
Expand|Select|Wrap|Line Numbers
  1. Private Sub chkSomeCheckbox_AfterUpdate()
  2.     Call updateTimeSheet()
  3. End Sub
If you don't want to mess with this, I will understand.
Dec 21 '15 #10
SixHat
7
@Zmbd, @JForbes For sure... I've actually made the changes already but can draw it back as it's in source control... so I'll give'em a try and let you know. I probably will not have time to do this until tomorrow... but I'll be sure to keep you both posted. Thanks
Dec 22 '15 #11
SixHat
7
Customer was a little behind this morning so had time to give it a try now.

@Zmbd... DBEngine.Idle dbRefreshCache did not work. I tried it with DoEvents and without...

@JForbes Thanks for the info on Split Forms... I was not aware that it was constructed that way... but now that you explain it... it makes sense with some of the weird behavior that I've seen them display in the past...

In trying your code my first instinct was to make your Public Sub Private... but after stepping through it I quickly understood why you made it public so switched it back...

If you had not explained how split forms were constructed the code would have not made sense as it's a procedure calling itself... but after the explanation I was really hopeful and thought for sure that it would work... To my great disappointment however it did not. I even tried throwing in a Me.Requery but that did not get it either.

Thank both of you for your time and help
Dec 22 '15 #12
zmbd
5,501 Expert Mod 4TB
That's most unfortunate - thank you taking the time to try both J's and my suggestions - we can't win them all :)
-z
Dec 22 '15 #13

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

Similar topics

1
by: DevilZAngel | last post by:
Hi all I am writing a simple chat application in asp.net. Problem is that, when other user sends a message, I want my testbox (which shows the messages) to refresh automatically, without using...
0
by: Mark Payne | last post by:
Gudday, I have an Access 2000 database which I am using as a phone directory of residents in the hostel where I work. The front end for this directory is a form with a text box (the search name...
1
by: Dmitry Karneyev | last post by:
Hi! How to force refreshing databinded controls of the win form?
4
by: John Tyce | last post by:
The problem that I am now having, involves refreshing controls. I have allot of text boxes, several combo boxes and grids. These controls are showing live data from an Oracle database. I have dates...
4
by: Dan Baker | last post by:
I have a form with several controls. I would like to paint *over* several controls (mainly GroupBoxes and Labels). But, Everywhere I try to perform painting, I end up "behind" the controls. I need...
5
by: Dranreb | last post by:
Hello, I use a template whereby my default page contains various user controls - i.e. "Header", "Footer", "Navigation", "Content". On some occaisions I'd like to manipulate the other controls...
6
by: Chris Moore | last post by:
I have a .NET form where I am updating a progress bar & counter. As long as the form never loses focus, everything on the form refreshs fine. But If I open another window (like Windows Explorer)...
1
by: Harlan Messinger | last post by:
If I have a dropdown list ddl, and the following code appears in Page_Load, then on each postback the rows previously added persist and I wind up with more and more copies of the same rows. To...
1
polymorphic
by: polymorphic | last post by:
I've seen allot of posts about refreshing controls but I can't seem to get mine to refresh. I'm using VS2005 and I have a bindingSource attached to my controls. I update my dataset and cal...
2
by: =?Utf-8?B?R3JlZw==?= | last post by:
I have the following code the dynamically adds a specific number of controls. for x as integer = 1 to 10 Dim btn as Windows.Forms.Button = New Windows.Forms.Button btn.Name = "btn" & x btn.Text...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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...

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.