One form switched between two queries

BarryMK

4 strings are enough
Local time
Today, 01:53
Joined
Oct 15, 2002
Messages
1,350
Access 97 Is it possible to switch from the underlying query to another by using a command button on a form, and if so how would I code it? Thanks
 
Try the following on the click property of the button:

Me.RecordSource = "newqueryname"
 
Blimey That was quick. Thanks I'll give it a whirl. Cheers:D
 
Keith Thank you I finally got time to try your code it works a treat. Easy isn't it when it does what you want?
 
Yippee! I've almost completed my latest database and with help from the forum it's more automated and sophisticated than anything I've achieved before. But........Just one more tweak and I'll turn it loose on the dreaded users.

Keith I used your code here.

I have a form "Input" with two command buttons in the form header. These select either of two record sources for the form.

Just to make things difficult I would like to display the name of the record source which has been selected. I've tried various things but am completely stumped. Nothing new there then......

The on Click code to pick the record source is below.

'selects query source for input form
Private Sub Command105_Click()
Me.RecordSource = "AllRecords"
End Sub

'selects query source for input form
Private Sub Command106_Click()
Me.RecordSource = "Shops"

Any bright ideas folks??
 
Create a new label. My example names the new label "lblRecordSource".

'selects query source for input form
Private Sub Command105_Click()
Me.RecordSource = "AllRecords"
Me.lblRecordSource.Caption = "All Records"
End Sub

'selects query source for input form
Private Sub Command106_Click()
Me.RecordSource = "Shops"
Me.lblRecordSource.Caption = "Shops"
End Sub

You should consider using a standard naming convention for your objects.
ie...Command106_Click = btnRecordSource_Click

HTH
 
Lovely! Once again the forum comes up trumps. I 've been looking at various combinations of fields and bits of code, it would not have occurred to me to use a label instead. Thanks for the advice on naming but I'll save that for the next database!:D
 
Barry - glad you got it sorted.

An alternative method I have developed for indicating which of 2 (or more) buttons is active, is to create a little rectangle immediately above each, coloured to look like an indicator lamp, and have only the appropriate one visible at any one time.

Regards

Keith
 
Like traffic lights Eh? I Like it.
 

Users who are viewing this thread

Back
Top Bottom