Full Version: VBA and Command button
UtterAccess Forums > Microsoft® Access > Access Forms
oilers90
I am trying to create a button that when it is clicked, it will move the user through a recordset to get the ID and then call the function to get the next teamplayer. I was wondering if anyone can explain to me the difference between FindNext and MoveNext since I think this is where the problem exists.
GroverParkGeorge
FindNext moves focus to the next record in the recordset which matches the critierion you specify. If you use FindNext, you must specify what you want Access to find.
oveNext moves focus to the next record in the recordset, without regard to any other criterion.
George
oilers90
So if I want to select the next PositionID from a query in order to retrieve a teamplayer, I would use MoveNext.
o my syntax would look like this possible:
rstTeamPosition.MoveNext (PositionID)
GroverParkGeorge
rstTeamPosition.MoveNext
ill move focus to the next record in the recordset.
To retrieve the team player from that record, however, you need to have something like this as the next line after the move.
intPlayerID = rstTeamPosition!PositionID
HTH
George
oilers90
So maybe I am going about this the wrong way. I am trying to use a recordset based on a SQL statement to retrieve information from the database.
asically what I want to be able to achieve is that once the button is clicked, a new team player appears based on the recordset. I want the user to get the PositionID and then retrieve the team player.
GroverParkGeorge
When you say, "a new team player appears", do you mean you want to display the player's information in a form?
oilers90
Just the name of the player based on the PositionID.
For example...there would be a section of the form for goalie...once the command button is clicked, it moves to the next goalie that appears from the query.
GroverParkGeorge
Oh, okay. You only mentioned recordsets before, which led me to misunderstand what you are trying to accomplish. Sorry.
But now I'm a bit confused about something else. The recordset for the form (i.e. the query which provides records for the form) is already filtered by PositionID, correct? Or do you want the command button to requery the table for a different PositionID and then search?
oilers90
I want it to do the later. I wanted to be back into the query and and select the next PositionID. The only thing is that on the form, it does not show the PositionID. It only shows the first name and last name of the team player.
GroverParkGeorge
If I understand correctly then, you need to do two things:
Select the next positionID (regardless of what that position is?)
Select the next player who fills that position (regardless of which player that is?.
oilers90
Exactly
GroverParkGeorge
Okay, so then this is a two part function. MoveNext will only work for the step in which you select the next position. Give me a few minutes to work this out.
GroverParkGeorge
Sorry about the delay. WOrk keeps interrupting.
Here's a demo of ONE technique to do what you described. Since I don't know what tables you actually have in your database, I created tables based on what I think they should probably look like.
HTH
George
oilers90
Thanks GroverParkGeorge. I will give it a try and let you know.
GroverParkGeorge
I hope you can glean some ideas from the techniques there, even if they don't match up exactly with your existing tables. Good luck.
eorge
This is a "lo-fi" version of UA. To view the full version with more information, formatting and images, please click here.