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 derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Dynamically setting a form command button onclick event

Status
Not open for further replies.

dpimental

Programmer
Jul 23, 2002
535
US
I need to dynamically set a form command button's onClick event from an outside module. How do I set it?

David Pimental
(US, Oh)
 
Well, here's what I am doing.

I have a list control who's record source is based on search criteria from the user. I can open the form set the record source of the ListView object no problem.

My problem is this. When viewing all records, I've created command buttons that allow the user to view a set of records (20) at a time.

So the button onClick event fills the ListView based on a specific record source. I need to be able to chane that on-the-fly.


David Pimental
(US, Oh)
 
Wouldn't it be easier to just programmatically build the RecordSource for the ListView?


-V
 
I did that already. But I know that the number of records will be in the few hundreds. So, this is just a cleaner approached and alternative to having some one scroll through 60, 70, 80 records, even though they have pick a specific criteria to filter it.

But any suggestions would help.

If I have 500 cars and they want to see all the ford cars (not sure why but if they do) then that might be 150 - 200 records to scroll through. Or my method would just display the top 25, the next button would display the next 25 and so on. Any ideas?

David Pimental
(US, Oh)
 
Hi David,

Here is a method to solve your problem:

Insert Text On control of another form:
Forms.frmTargetFormCalled.ListBox.RecordSource = "Your SQL"
Forms.frmTargetFormCalled.ListBox.RecordSource.Requery

Where 'frmTargetFormCalled' is the name of the form
and 'ListBox' is the name of the list control on that form.

Hope this helps,
Hap...


Access Developer [pc] Access based Accounting Solutions - with free source code
Access Consultants forum
 
First off, I would never call modifying sub routines on-the-fly as clean.

I was going to refer you here: thread705-1393675 but then I realized that was you.

I assume you are trying to implement those queries. It would probably be easiest to just keep a variable that you increment by whatever amount you want:

Code:
sqlStr = "SELECT TOP FieldName " _
   & "FROM yourTable " _
   & "WHERE FieldName NOT IN " _
   & "  (SELECT TOP " & [i]variableName[/i] & " FieldName FROM yourTable)"



-V
 
Thanks for all the help so far. Perhaps I should clarify a few things.

First, to understand my idea of "clean", you'd have to see my car.

Now to the more important stuff.

There are 2 different ways I'm limiting the output of the records.

1. By the user selecting car type, model or year.

2. By the number of records found.

The paging solution works for the total records, but not for the 1st criteria, which changes each time.

Maybe I could use a hidden cotrol and popluate it with the criteria and then use it on the onClick event for each button?

David Pimental
(US, Oh)
 
The paging solution can work just fine with criteria. Example:

Code:
SELECT TOP 25 CarIndex 
    FROM tblCars
    WHERE CarModel = 'Mazda 626'
        AND CarIndex NOT IN 
        (SELECT TOP 25 CarIndex FROM tblCars WHERE CarModel='Mazda 626');


-V
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top