Solved

How to populate unbound controls on a continuous form in Access 2007

Posted on 2009-05-03
9
1,331 Views
Last Modified: 2013-11-28
I have a continuous form bound to a non-updatable recordset.  Let's assume for a moment that there's a really good reason for that and there's no easy way to either make the recordset updatable or to bind the form to a temp table.

I want to make two of the textbox controls on this form unbound, but assign them a value from the underlying form record source as they are displayed.  Since they are unbound I'll be able to edit values in these textboxes and use textbox events to execute some SQL to update the real values in the underlying tables.

I've been trying to make this assignment in the OnPaint event of the detail section of my form and this does in fact work, but generates huge flicker because I'm guessing the assignments are causing other paint events to get fired.  Anyone have experience trying to do what I'm trying to do and have any suggestions?  I tried setting a module level variable with the record key and only letting the OnPaint event update the values once per record but this seems to have no effect (see the code section for my OnPaint event.
Private Sub Detail_Paint()

    'On Error Resume Next

    

    If mlngSplitID <> Me.SplitID Then

        Me.tbSplitAmount = Me.SplitAmount.Value

        Me.tbOfficeCode = Me.OfficeCode.Value

        mlngSplitID = Me.SplitID

    

        If Me.SplitError = -1 Then

            Me.tbSplitAmount.BackColor = vbRed

        Else

            Me.tbSplitAmount.BackColor = vbWhite

        End If

    End If

End Sub

Open in new window

0
Comment
Question by:kmslogic
  • 5
  • 2
  • 2
9 Comments
 
LVL 77

Expert Comment

by:peter57r
ID: 24293103
If you use unbound controls on a continuous form, then every record will display the same values in these controls  - so you cannot show different values in different records.
Is that going to be OK?
0
 
LVL 16

Author Comment

by:kmslogic
ID: 24293344
Well no that's not ok, and like I said if you set the values of the unbound controls in the OnPaint event of the detail section of the form then you can get different values on each row.  The problem is that it causes the whole form to continuously flicker.

I use the same technique to set the background color of certain cells red when the values are in error and that works great without flicker, so it's the actual setting of a value that for some reason does it.


0
 
LVL 16

Author Comment

by:kmslogic
ID: 24293363
I've created a sample Access 2007 database that shows what I'm talking about.  Just a little table and a form with just the OnPaint event and two lines of code...  Ok nice experts_exchange can't handle the accdb extension... Well done.  Ok uploading it in 2003 format...



OnPaintExample.mdb
0
 
LVL 77

Accepted Solution

by:
peter57r earned 500 total points
ID: 24333899
That's quite interesting, although it's obviously based on an optical illusion (I suppose you could justifiably respond by saying all perception of screen content is based on an optical illusion(:-) ).

I don't know if MS expected this new event to be used in this way and unless thay did, I guess they would say that the feature is 'working as intended'.

I can't think of anything you could change to remove the flicker (short of running the app on the most powerful hardware around, and seeing if that improved the refresh rate)
0
Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
LVL 16

Author Comment

by:kmslogic
ID: 24334734
what's interesting to me is that if you just change the background color of cells this works entirely without flicker (and is quite useful).  Somehow putting text in the control is causing some sort of unintended event loop.
0
 
LVL 1

Expert Comment

by:jjeldridge
ID: 25252378
KMSLogic,  Did you ever can an answer or workaround on this question?  I am experiencing the same problem
0
 
LVL 16

Author Comment

by:kmslogic
ID: 25358734
Sorry it just looks like this approach isn't doable.  I'm assigning the points to peter for pointing out the undoableness of using the onpaint event for this purpose.
0
 
LVL 1

Expert Comment

by:jjeldridge
ID: 25365548
I agree that the onpaint will not work.  What is actually happened is an infinited painting loop as you fill in the unbound control (in triggers on the paint event...which triggers the code to fill the control...which triggers on the onpain event and so on.)

My particular problem, in which I was using an unbound control, was trying to pop a value based on my underlying table into an unbound control on the multiform page.  I was trying to use code initially (and thus the onpaint event) but then it occurred to use a view instead of a table as the datasource for the form.  I had thought, in doing this, I wouldn't be able to edit the data; but you can as long as you formulate the view correctly.  So with the view, I bring my table's data and then I join in the value I wanted to place in the unbound control.  Everything works fairly well.

There is a small issue with how updates work that is a little ugly because of this architecture; but I think, even that, can be smoothed out.

I'm not looking for points...just wanted to offer what my workaround was.
0
 
LVL 16

Author Comment

by:kmslogic
ID: 25365788
Well my situation was one where the recordset I was using wasn't updatable.  In your case it sounds like you came up with one that was which is great.  There are many situations in Access where a view/query will be non updatable even if you include the key fields from all the underlying tables in it (what I assume you mean by 'the right way')
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

The first two articles in this short series — Using a Criteria Form to Filter Records (http://www.experts-exchange.com/A_6069.html) and Building a Custom Filter (http://www.experts-exchange.com/A_6070.html) — discuss in some detail how a form can be…
Introduction The Visual Basic for Applications (VBA) language is at the heart of every application that you write. It is your key to taking Access beyond the world of wizards into a world where anything is possible. This article introduces you to…
Using Microsoft Access, learn some simple rules for how to construct tables in a relational database. Split up all multi-value fields into single values: Split up fields that belong to other things into separate tables: Make sure that all record…
In Microsoft Access, learn different ways of passing a string value within a string argument. Also learn what a “Type Mis-match” error is about.

747 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now