Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Is there a way to speed up this line?

Status
Not open for further replies.

chunter33

Programmer
May 16, 2011
44
CA
This might be a shot in the dark, but is there a way for me to speed up this snippet of code? Even a second would count, as this code gets called repeatedly.

Code:
Me.RecordSource = "SELECT * FROM [" & tbl_task_table & "] where [Task ID] = " & curw_rs.Fields(1).value & ";"[code]

I tried to select directly from the table itself as opposed to accessing it through the record set's name propety. Turns out that was even slower.
 
what fields are in the table? Is there any code in the Form's Current Event? (the current event fires as soon as you reset the recordsource as you are above) The statement "as opposed to accessing it throught the recordset's name property" doesn't really make sense...can you clarify and give more background on what you're doing?
 
Ah, I see why that wouldn't make sense. The snippet of code I put up there was the modified version, and not the original and the "tbl_task_table" part should be surrounded in quotes.

Originally it was this:

Me.RecordSource = "SELECT * FROM [" & curw_rs.name & "] where [Task ID] = " & curw_rs.Fields(1).value & ";"

Background:

I have a form with a number of controls that are dynamically being unbounded and rebounded repeatedly. Both the unbinding and the rebinding was slow, but I managed to speed things up by making better use of the forms recordsource. Instead of constantly setting each controls controlsource to blank to unbind it, I simply set the forms recordsource to an empty copy of the table it's supposed to be populating all of it's controls from and then perform a requery on each control.

The only thing that is still running somewhat slow is the line above. However, I don't think there's any faster alternative to this. I hope somebody can prove me wrong.
 
How ae ya chunter33 . . .
[ol][li]Because your concatenating the tablename you can't goto query for speed.[/li]
[li]Do you have to select [blue]All[/blue] (*). Selecting 4 fields is a big difference from selecting over one hundred.[/li]
[li]Are you returning a large recordcount (10,000 or 100,000 records or more?) You may not be able to circumvent this.[/li]
[li]I don't know the ins/outs of the recordset your using ... but surely ... once you update the [blue]RecordSource[/blue] the recordset no longer matches the data in the form. This may/maynot be a problem.[/li][/ol]
[blue]Your Thoughts? . . .[/blue]


See Ya! . . . . . .

Be sure to see faq219-2884 [blue]Worthy Reading![/blue] [thumbsup2]
Also faq181-2886 [blue]Worthy Reading![/blue] [thumbsup2]
 
Selecting only the fields I need sounds like a great idea. I can't try this at the moment as I'm not in the office but I'll surely give it a try at some point this week.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top