Solved

MS Access Control on Form

Posted on 2013-10-24
6
297 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
IT, Stop Being Called Into Every Meeting

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!

 

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

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

In the article entitled Working with Objects – Part 1 (http://www.experts-exchange.com/Microsoft/Development/MS_Access/A_4942-Working-with-Objects-Part-1.html), you learned the basics of working with objects, properties, methods, and events. In Work…
In Debugging – Part 1, you learned the basics of the debugging process. You learned how to avoid bugs, as well as how to utilize the Immediate window in the debugging process. This article takes things to the next level by showing you how you can us…
In Microsoft Access, learn how to use Dlookup and other domain aggregate functions and one method of specifying a string value within a string. Specify the first argument, which is the expression to be returned: Specify the second argument, which …
In Microsoft Access, when working with VBA, learn some techniques for writing readable and easily maintained code.

706 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

13 Experts available now in Live!

Get 1:1 Help Now