Use only one form for three different queries (1 Viewer)

brunces

Registered User.
Local time
Today, 19:40
Joined
Sep 12, 2004
Messages
45
Friends,

Please, tell me if it's possible and how to do it.

- I have 1 table (tblProducts).
- I have 3 queries based on that table (qryProd1, qryProd2, qryProd3).
- Those 3 queries have the same structure, they are identical, but each one has different criteria for filtering records from tblProducts.
- I have 3 forms based on those queries (frmProd1, frmProd2, frmProd3).
- Those 3 forms also have the same structure, they are also identical, but each one is based on its respective query.
- I have a MENU (form) with 3 buttons (btnProd1, btnProd2, btnProd3). Each button opens its respective form.

Now, here is my point: Is it possible to use ONLY ONE FORM with 3 different queries? Not at the same time, of course. For example...

There would be only one form (frmProd).
When I click on btnProd1, the form frmProd should be opened, based on qryProd1.
When I click on btnProd2, the same form frmProd should be opened, now based on qryProd2.
And when I click on btnProd3, the same form frmProd should be opened, now based on qryProd3.

Is this possible? If so, how can I do it?

Thanks for your attention, guys. :)

Hugs,

Bruce
 

namliam

The Mailman - AWF VIP
Local time
Tomorrow, 00:40
Joined
Aug 11, 2003
Messages
11,695
Yes its possible. Look into the OpenArgs and even the Filter options of the Docmd.Openform command you are using to open the form(s) and you should be able to figure it out from there.

If you have specific questions after checking the help, post back here.

:D
 

brunces

Registered User.
Local time
Today, 19:40
Joined
Sep 12, 2004
Messages
45
I'm sorry, namliam, I'm a beginner. I really couldn't figure out how to do it using only the DoCmd.OpenForm. :(

If you don't mind, please, show me how to do it with an example. :)

Thanks for your attention.

Hugs,

Bruce
 

namliam

The Mailman - AWF VIP
Local time
Tomorrow, 00:40
Joined
Aug 11, 2003
Messages
11,695
I'm a beginner.
No shame in that... but you wont learn (much) if other people allways give you the answers, you would just be applying their knowledge and changing stuff a little. I think that is both no fun and gives you no (or very little) pride.

So check out the openform command in the help and read that. Then look at the example given there and see if you can get anywhere with that example.
I will be glad to help you if you get stuck ! :D
 

brunces

Registered User.
Local time
Today, 19:40
Joined
Sep 12, 2004
Messages
45
namliam,

I respect your words, but believe me, when I put a question in a forum, it's because I've already tried everything I know, but really couldn't make it on my own, unfortunately.

And, believe me again, I wish I knew how to do everything I want by myself, without asking for anybody's help, but unfortunately (or fortunately) I'm still learning and still have much to learn, so I still need help.

I'd like to tell you that I've already made it, but not with the solution you suggested me. Today, I searched the help for something related to "source" and I found the property "RecordSource".

Here's what I've already created:

- One table (tblNames)
- Two queries (qryByName, qryBySurname)
- Two forms (frmMenu, frmNames)
- frmMenu has two buttons (ByName, BySurname)
- One public variable (strDataSource)

Here are the codes:

Code:
Button ByName Code:
strDataSource = "ByName"
DoCmd.OpenForm "frmNames"

Button BySurname Code:
strDataSource = "BySurname"
DoCmd.OpenForm "frmNames"

frmNames Code:
Private Sub Form_Load()
    Select Case strDataSource
        Case "ByName"
            Me.RecordSource = "qryName"
        Case "BySurname"
            Me.RecordSource = "qrySurname"
        Case Else
            Me.RecordSource = "tblNames"
    End Select
End Sub

These codes worked pretty well. But I confess I'm still curious about your DoCmd.OpenForm command solution. If you still want to help, I'll appreciate it. If not, never mind. That's OK.

You said we don't learn (much) when other people always give us the answers... That's true, but I thank God I was born after Einstein, Isaac Newton, Thomas Edison and many others, and didn't have to figure out how to create everything they created by myself. And you? :)

Thanks for your replies.

Hugs,

Bruce
 

namliam

The Mailman - AWF VIP
Local time
Tomorrow, 00:40
Joined
Aug 11, 2003
Messages
11,695
Thats one way of doing it, good for you on figuring that one out.

Click on the OpenForm statement and hit F1, this opens the help for OpenForm
You will find as the last option the OpenArgs argument. You can use this to parse any string you desire... Like so...
docmd.OpenForm "frmNames",,,,,,"qryName"

Then in your Form load you can read your OpenArgs argument and use it.
me.Recordsource = Me.Openargs

I dont know what the difference is between the 2 queries and/or the table. But it is likely a sort or something? This you can also do on the form itself.
Me.OrderBy= "[Fieldname]" ' Fieldname to sort on
Me.OrderByon = true ' Apply the sort, false will turn it off again

The same aplies for filters, using the Filter and FilterOn commands.

I hope this is clear enough.... and is more helpfull.

Greets
 

brunces

Registered User.
Local time
Today, 19:40
Joined
Sep 12, 2004
Messages
45
namliam,

This method of yours is very cool and works very well. Now I understood how it works.

Thank you very much for your attention. I appreciate it.

Hugs,

Bruce
 
Last edited:

raskew

AWF VIP
Local time
Today, 17:40
Joined
Jun 2, 2001
Messages
2,734
Bruce -

Does 'hugs' mean something different in Brazil than it does in the US?

Might be OK if you kept your sexual orientation to yourself, no ask, no tell. This is a Microsoft Access forum. Could we just keep it at that?

Bob
 

brunces

Registered User.
Local time
Today, 19:40
Joined
Sep 12, 2004
Messages
45
raskew,

'Hugs' mean 'hugs' in Brazil and, not necessarily, mean physical relationship.

Using the word 'hugs' at the end of a message is a gesture of politeness or gentleness (not 'gayness' as you might have thought).

Now, tell me, raskew, being polite or gentle means something different in the US than it does in Brazil?

Yes, this is a Microsoft Access forum and we deal with people here, not machines. I guess there's nothing wrong on being kind with each other.

(...),

Bruce
 

Users who are viewing this thread

Top Bottom