Link to home
Start Free TrialLog in
Avatar of jpbay
jpbay

asked on

Need help editing SQL query criteria in VB

I'm building a database for some language translation teams to track their requests and see how much time they're spending on them. On the main form are some buttons for each team to go to their respective home form. I would like to set it up so that when the Team's home form opens, it adds the criteria of that specific language before running the queries, then displays only their records.

For example, each Team home form has a list box with all the members on that team (it's a list box so others can double-click a name and it pulls up a form with that member's contact information). I would like to have it so that when someone clicks the Spanish Team button on the main form, it pulls up frmSpanishTeamHome and displays only the Spanish team members. I realize that I could do this with separate queries for each team, but that would add up to a LOT of queries.

So I have qryMembers that pulls all the records in tblMembers, and I would like the form VB to change the criteria of qryMembers based on which Team button was clicked on.

I've hunted around for a solution and found a couple that looked promising, but there was always one or two little things that made them not work. For example, I tried setting up the code so it would pull the SQL from the query into a variable and then just add on the WHERE clause, but the query always saved with a ; at the end, making any additions after the variable error out.

So if anyone has any ideas, I would greatly appreciate it!
Avatar of Arji
Arji
Flag of United States of America image

If you have a foregin key value for nationality of team members that should be faiirly simple:

team mmber table example

TeamMemberID  [PK]
NationalityID        [FK

When you open the Spanish Team form your can send the form a 'message' using the OpenArgs parameter:

DoCmd.OpenForm "frmSpanishTeamHome" ,,,,,"Spanish"      '<---OpenArgs parameter

Now in the On Open event of frmSpanishTeamHome:

if Not IsNuul(Me.OpenArgs) then

   Me.YourMemberList.RowSource  = "select * from qryMembers where Nationality='" & Me.OpenArgs & "'"

end if

In order to do this you MUST somehow identify each member's natianality or language and use that as the foreign key to build your lists.  You may have to add a Natianiltiy  or Language field in your tblMembers and add it to your qryMembers.  
Avatar of jpbay
jpbay

ASKER

I tried this (and tried fiddling with it some to get it just right), but then it made the entire list box blank - no names at all. Any ideas?

I do have a TeamID field in the tblMembers that hooks up to a separate table with the actual language names, do I need to put the ID number or the name in the OpenArgs parameter? Should I change it in the table to be the name instead of a number?

I found a way to make it work by just having the rowsource for the list box be the SQL that you gave me (minus the OpenArgs piece), but I would like to be able to have this form automated so that it's just one form and what is displayed changes based on which language buttons are clicked on the main form. If that's too complicated (shouldn't be, once I learn how to do the code right), I can have different forms for each language.
ASKER CERTIFIED SOLUTION
Avatar of Arji
Arji
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of jpbay

ASKER

Thanks so much, Arji! It works perfectly. :-) I'll play around with OpenArgs and see what I can make it do for me.