By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,264 Members | 1,087 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,264 IT Pros & Developers. It's quick & easy.

Refreshing rowsource of combobox on the fly in ms access 2007

P: 99
I have a combobox on a form which has to change its rowsource at run time on the basis of a particular label selection.I have managed to do the same but the problem is that it takes time to requery the combobox.If the selection of the label changes, the combobox record points out to the same records as previous one.Only after click on other controls does the records are as expected.I have used this:
Expand|Select|Wrap|Line Numbers
  1. Me.cboOverdueID.Rowsource.Requery
  2. Me.Refresh
It would be great if the reocrd changes happen quicker.
Mar 3 '12 #1
Share this Question
Share on Google+
7 Replies


Expert Mod 2.5K+
P: 2,545
First, I doubt you need the Me.Refresh method call - assuming that the label change you refer to is in your own instance of the database. Refresh is only really necessary if other DB users have modified the records in the underlying recordset and you want the data in your form's recordset to match.

The requery is all you need to update the combo itself.

Second, the requery method may take some time if it is based on something complex - like a query that does a lot of calculation, say - or that has many thousands of rows. Combos don't often need complex recordsources, in which case a requery may run much faster than, say, requerying the recordsource of the form itself.

Perhaps if you posted more details of the SQL for the combo's recordsource and what is changing on the form we could assist you more.

-Stewart
Mar 3 '12 #2

P: 99
here's one of the queries:
Expand|Select|Wrap|Line Numbers
  1. SELECT tblWO.A_ID, tblLOCATIONS!Platform_ST & "-" & tblWO!A_ITEMNO AS ID, FormatDateTime([A_DATEOPEN],2) AS Raised, tblWO.A_PRIORITY AS P, tblWO.A_ManhrsEst AS hrs, tblWO.A_DESCR AS Descr, tblWO.A_DATEGOAL FROM tblLOCATIONS INNER JOIN tblWO ON tblLOCATIONS.Platform=tblWO.A_LOCATION WHERE (((tblWO.A_DATEGOAL)>=Now() Or (tblWO.A_DATEGOAL) Is Null) AND ((tblWO.A_COMPLETION)<>100) AND ((tblWO.A_MANCLOSE)=No) AND ((tblWO.A_LOCATION)>IIf(getasset()=" & "**ALL**" & "," & "a" & "," & "zz" & ") Or (tblWO.A_LOCATION)=getasset())) OR (((tblWO.A_DATEGOAL)>=Now() Or (tblWO.A_DATEGOAL) Is Null) AND ((tblWO.A_COMPLETION) Is Null) AND ((tblWO.A_MANCLOSE)=No) AND ((tblWO.A_LOCATION)>IIf(getasset()=" & "**ALL**" & "," & "a" & "," & "zz" & ") Or (tblWO.A_LOCATION)=getasset())) ORDER BY tblWO.A_PRIORITY, tblWO.A_ITEMNO
Mar 5 '12 #3

NeoPa
Expert Mod 15k+
P: 31,494
Please see [code] Tags Must be Used before posting again.
Mar 5 '12 #4

Expert Mod 2.5K+
P: 2,545
You have a complex WHERE clause in the rowsource of your combo, which will undoubtedly slow requery performance down. Breaking it into its components, you have:

Expand|Select|Wrap|Line Numbers
  1. (((tblWO.A_DATEGOAL)>=Now() Or 
  2. (tblWO.A_DATEGOAL) Is Null) AND 
  3. ((tblWO.A_COMPLETION)<>100) AND 
  4. ((tblWO.A_MANCLOSE)=No) AND 
  5. ((tblWO.A_LOCATION)>IIf(getasset()=" & "**ALL**" & "," & "a" & "," & "zz" & ") Or 
  6. (tblWO.A_LOCATION)=getasset())) OR 
  7. (((tblWO.A_DATEGOAL)>=Now() Or 
  8. (tblWO.A_DATEGOAL) Is Null) AND 
  9. ((tblWO.A_COMPLETION) Is Null) AND 
  10. ((tblWO.A_MANCLOSE)=No) AND 
  11. ((tblWO.A_LOCATION)>IIf(getasset()=" & "**ALL**" & "," & "a" & "," & "zz" & ") Or 
  12. (tblWO.A_LOCATION)=getasset()))
I would concentrate on simplifying these conditions. If you have to specify all this just for the combo to work correctly there is something amiss in the underlying logic for your form or the combo or both!

Ask yourself what does the combo really have to contain, where can you get it, and what conditions if any are required for that combo.

It is difficult to give more advice on this without seeing your application or knowing how your form is set up. As you have a detailed knowledge of your application you are better placed than we are to sort out these complex conditions.

-Stewart
Mar 5 '12 #5

NeoPa
Expert Mod 15k+
P: 31,494
Furthermore, function calls within a WHERE clause should be avoided where possible. They can be very delaying.

You may find it easier to simplify if you get rid of all the pointless concatenations of literal strings. #1 below is much easier to work with than #2, and there is no possible benefit to writing code as #2 :

Ooops. It turns out I can't illustrate a better version for #1 as it makes absolutely no sense in SQL anyway. It is wholly faulty SQL and I'm surprised it could ever run.
  1. Expand|Select|Wrap|Line Numbers
    1. Impossible to make sense of
  2. Expand|Select|Wrap|Line Numbers
    1. ((tblWO.A_LOCATION)>IIf(getasset()=" & "**ALL**" & "," & "a" & "," & "zz" & ")

Clearly this turns out to be rubbish anyway, as in it isn't valid SQL, and I'm surprised you haven't got an error message to share with us instead of reports of delays.
Mar 5 '12 #6

P: 99
Yes I did get error messages and change the query to the following and it works perfect:
Expand|Select|Wrap|Line Numbers
  1. Me.frmWOMAINSUBMENU.Form.RecordSource = "SELECT tblWO.A_ID, tblLOCATIONS!Platform_ST & ' - ' & tblWO!A_ITEMNO AS ID, FormatDateTime([A_DATEOPEN],2) AS Raised, tblWO.A_PRIORITY AS P, tblWO.A_ManhrsEst AS hrs, tblWO.A_DESCR AS Descr FROM tblLOCATIONS INNER JOIN tblWO ON tblLOCATIONS.Platform=tblWO.A_LOCATION WHERE (tblWO.A_COMPLETION <> 100 AND tblWO.A_MANCLOSE=0 AND (tblWO.A_LOCATION > IIf('" & GetAsset() & "'='**ALL**' ,'a', 'zz') Or tblWO.A_LOCATION ='" & GetAsset() & "') AND (tblWO.A_DATEGOAL < " & Format(Now, "\#mm\/dd\/yyyy hh\:nn\:ss\#") & ") OR (tblWO.A_COMPLETION Is Null AND tblWO.A_MANCLOSE=0 AND (IIf('" & GetAsset() & "'='**ALL**' ,'a', 'zz') Or tblWO.A_LOCATION= '" & GetAsset() & "')) AND (tblWO.A_DATEGOAL < " & Format(Now, "\#mm\/dd\/yyyy hh\:nn\:ss\#") & ") ) ORDER BY tblWO.A_PRIORITY, tblWO.A_ITEMNO"
  2.  
Mar 6 '12 #7

NeoPa
Expert Mod 15k+
P: 31,494
You posted SQL you knew didn't work, without even mentioning that, somewhat fundamental, fact. Nice.
Mar 6 '12 #8

Post your reply

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