Solved

VBA script to dynamically change the SQL "Record Source" query on a form using radio buttons

Posted on 2006-11-08
5
498 Views
Last Modified: 2008-01-16
At the moment I have 3 forms all with the same graphical presentation.
They query the same data set.
The only difference between the forms is the "Record Source" SQL statement used.

I'd like to consolidate these forms into one form with three radio buttons allowing selection of the "Record Source" SQL statement with the appropriate data refresh that is necessary afterwards.

Does anyone have the VBA for this.

Regards

Kes3

0
Comment
Question by:kes3
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
5 Comments
 
LVL 77

Accepted Solution

by:
peter57r earned 500 total points
ID: 17896448
Hi kes3,


In the option group frame afterupdate event:


Dim rs1, rs2,rs3
rs1= "Select..........."
rs2 = "Select.........."
rs3 = "Select........."

me.dirty = false ' saves any unsaved changes

Select case me.optiongroupnamehere
Case 1
me.recordsource = rs1
Case 2
me.recordsource = rs1
Case 3
me.recordsource = rs1
End select


Pete
0
 

Author Comment

by:kes3
ID: 17897575

Thanks Pete

I inserted an "option group" with three radio buttons. Then, again in design view I selected the outer perimeter of this "option group", right clicked and chose properties. This shows the "option group" has    Name = Frame43.
I then clicked the "Event Tab" and Selected the three dots ... to the right of the "After Update" box and inserted your code amended as you suggest:

Private Sub Frame43_AfterUpdate()

Dim rs1, rs2, rs3
rs1 = "SELECT Issues.*, Contacts.[E-Mail Address] AS [assigned to e-mail], Contacts_1.[E-Mail Address] AS [opened by e-mail] FROM Contacts AS Contacts_1 INNER JOIN (Contacts INNER JOIN Issues ON Contacts.ID = Issues.[Assigned To]) ON Contacts_1.ID = Issues.[Opened By];"
rs2 = "OPEN ISSUES"
rs3 = "SELECT Issues.*, Contacts.[E-Mail Address] AS [assigned to e-mail], Contacts_1.[E-Mail Address] AS [opened by e-mail] FROM Contacts AS Contacts_1 INNER JOIN (Contacts INNER JOIN Issues ON Contacts.ID = Issues.[Assigned To]) ON Contacts_1.ID = Issues.[Opened By];"

Me.Dirty = False ' saves any unsaved changes

Select Case Me.Frame43
Case 1
Me.RecordSource = rs1
Case 2
Me.RecordSource = rs1
Case 3
Me.RecordSource = rs1
End Select

End Sub

I then tried it and Access does make calculations when I select any of the radion buttons howeve it produces the same result each time which is not what should happen.

Any ideas ?

Reagrds

Kes3
0
 
LVL 120

Expert Comment

by:Rey Obrero (Capricorn1)
ID: 17897639
{points to peter pls.}
you  are using the same recordsets for your recordsource
change rs1 to rs2 for case 2 and rs1 to rs3 for case 3

Select Case Me.Frame43
Case 1
Me.RecordSource = rs1
Case 2
Me.RecordSource = rs2
Case 3
Me.RecordSource = rs3
End Select

0
 
LVL 77

Expert Comment

by:peter57r
ID: 17897642
Sorry - my mistake -copy and paste strkes again!
You should be using rs1, rs2 and rs3 in the Case statement.
Select Case Me.Frame43
Case 1
Me.RecordSource = rs1
Case 2
Me.RecordSource = rs2
Case 3
Me.RecordSource = rs3
End Select

Pete
0
 

Author Comment

by:kes3
ID: 17897903


Many Thanks folks. I was about to paste rs1 ...rs3 necessary changes back here ....

Regards

Kes3
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In a multiple monitor setup, if you don't want to use AutoCenter to position your popup forms, you have a problem: where will they appear?  Sometimes you may have an additional problem: where the devil did they go?  If you last had a popup form open…
As tax season makes its return, so does the increase in cyber crime and tax refund phishing that comes with it
Learn how to number pages in an Access report over each group. Activate two pass printing by referencing the pages property: Add code to the Page Footers OnFormat event to capture the pages as there occur for each group. Use the pages property to …
With Microsoft Access, learn how to start a database in different ways and produce different start-up actions allowing you to use a single database to perform multiple tasks. Specify a start-up form through options: Specify an Autoexec macro: Us…

734 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question