Solved

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

Posted on 2006-11-08
5
467 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
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 119

Expert Comment

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

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…
In Debugging – Part 1, you learned the basics of the debugging process. You learned how to avoid bugs, as well as how to utilize the Immediate window in the debugging process. This article takes things to the next level by showing you how you can us…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
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…

929 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

11 Experts available now in Live!

Get 1:1 Help Now