Solved

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

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

Three Reasons Why Backup is Strategic

Backup is strategic to your business because your data is strategic to your business. Without backup, your business will fail. This white paper explains why it is vital for you to design and immediately execute a backup strategy to protect 100 percent of your data.

Question has a verified solution.

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

Regardless of which version on MS Access you are using, one of the harder data-entry forms to create is one where most data from previous entries needs to be appended to new records, especially when there are numerous fields and records involved.  W…
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…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

831 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