Solved

MS Access Control on Form

Posted on 2013-10-24
6
303 Views
Last Modified: 2013-10-30
Hi

I have a form on which I am running a query which uses the value of one of the  form's  controls. This control is a calculated field.

On the first record all seems to work fine but after that it's as it the value is cached.

Thanks
0
Comment
Question by:ronnie10165
  • 3
  • 3
6 Comments
 
LVL 61

Expert Comment

by:mbizup
ID: 39596644
Can you be more specific?  ie: provide screenshots, code, queries, control sources etc (or even better - a sample database with any sensitive data masked or removed), so that we get a better picture of what you are working with?

The issue you are dealing with sounds like it boils down to the basic nature of controls... even though a control appears in multiple records, it is still only a single control - not multiple.  So at any given time a control has only one value, which is the value of the underlying field in the currently selected record.

There are a number of workarounds to this, but it is not clear what to suggest without knowing more about your application.
0
 

Author Comment

by:ronnie10165
ID: 39597741
Ok please take a look at the attachment

On form1 I want to look up  field value 2 in table2 where the value is greater than the field value1 in table1 and store the result in value3 in table 1.

[value1] in the expression does not seem to work

Thanks for your help
testing123.accdb
0
 
LVL 61

Expert Comment

by:mbizup
ID: 39597903
Ok -

Look at the rowsource property of your combo box, in SQL view.  This is what you currently have:

SELECT Table2.id, Table2.value2
FROM Table2
WHERE (((Table2.value2)>[value1]))
ORDER BY Table2.[value2];

Open in new window


The way you currently have it set up, the combo box is storing the ID, not the value.  If you want to store the value, change your row source SQL as follows and set the column count to 1:

SELECT Table2.value2
FROM Table2
WHERE (((Table2.value2)>[value1]))
ORDER BY Table2.[value2];

Open in new window


That said...the way you currently have this working is the preferred/best approach 99.9% of the time (store the ID and lookup the text/value on an as-needed basis), and the change you are asking for has its place but in many applications is not the best approach.
0
Enterprise Mobility and BYOD For Dummies

Like “For Dummies” books, you can read this in whatever order you choose and learn about mobility and BYOD; and how to put a competitive mobile infrastructure in place. Developed for SMBs and large enterprises alike, you will find helpful use cases, planning, and implementation.

 

Author Comment

by:ronnie10165
ID: 39598024
Hi I want to store the ID, the thing is the where part of the SQL statement does not work.

WHERE (((Table2.value2)>[value1]))
0
 
LVL 61

Accepted Solution

by:
mbizup earned 500 total points
ID: 39598193
Boy did I misunderstand your request!  :-)

The issue is that the lists in combos and listboxes (the rowsource property) does not automatically refresh as the user navigates between records - so you see the same list that is populated initially when the form opens, regardless of what record you are on.

You can use VBA to requery the row source when the record changes.

In the form's property sheet, under the Events Tab, click the ... next to On Current and select Code Builder.  Then place a requery statement between the Sub and End Sub lines.  It should look like this when done, replacing "Combo5" with whatever the actual name of your combo is in your application:

Private Sub Form_Current()
    Me.Combo5.Requery
End Sub

Open in new window

0
 

Author Closing Comment

by:ronnie10165
ID: 39613293
Thanks yes that's tested and working. Thanks for your help
0

Featured Post

Enterprise Mobility and BYOD For Dummies

Like “For Dummies” books, you can read this in whatever order you choose and learn about mobility and BYOD; and how to put a competitive mobile infrastructure in place. Developed for SMBs and large enterprises alike, you will find helpful use cases, planning, and implementation.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

In the previous article, Using a Critera Form to Filter Records (http://www.experts-exchange.com/A_6069.html), the form was basically a data container storing user input, which queries and other database objects could read. The form had to remain op…
Describes a method of obtaining an object variable to an already running instance of Microsoft Access so that it can be controlled via automation.
In Microsoft Access, learn how to “cascade” or have the displayed data of one combo control depend upon what’s entered in another. Base the dependent combo on a query for its row source: Add a reference to the first combo on the form as criteria i…
In Microsoft Access, learn the trick to repeating sub-report headings at the top of each page. The problem with sub-reports and headings: Add a dummy group to the sub report using the expression =1: Set the “Repeat Section” property of the dummy…

911 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