Solved

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

Posted on 2006-11-08
5
453 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
  • 2
  • 2
5 Comments
 
LVL 77

Accepted Solution

by:
peter57r earned 500 total points
Comment Utility
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
Comment Utility

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 119

Expert Comment

by:Rey Obrero
Comment Utility
{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
Comment Utility
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
Comment Utility


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

Regards

Kes3
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

In the article entitled Working with Objects – Part 1 (http://www.experts-exchange.com/Microsoft/Development/MS_Access/A_4942-Working-with-Objects-Part-1.html), you learned the basics of working with objects, properties, methods, and events. In Work…
Introduction When developing Access applications, often we need to know whether an object exists.  This article presents a quick and reliable routine to determine if an object exists without that object being opened. If you wanted to inspect/ite…
Familiarize people with the process of retrieving data from SQL Server using an Access pass-thru query. Microsoft Access is a very powerful client/server development tool. One of the ways that you can retrieve data from a SQL Server is by using a pa…
Using Microsoft Access, learn some simple rules for how to construct tables in a relational database. Split up all multi-value fields into single values: Split up fields that belong to other things into separate tables: Make sure that all record…

772 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now