473,395 Members | 1,977 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

Form with multiple queries

14
Hi,

Really appreciate some help with the following: ps I am very poor at VBA!

I have a form and when clicking a cmdbutton want to open the same form but with a different underlying query. I have looked some threads which just said look at Rowsource help which I have and am still none the wiser!

At the moment I have 3 forms with 3 queries and it's cumbersome obviously

In the form properties, I have removed the RecordSource data as I assume it will be populated by the VBA code

Expand|Select|Wrap|Line Numbers
  1. Private Sub Command10_Click()
  2. On Error GoTo Err_Command10_Click
  3.  
  4.     Dim stDocName As String
  5.     Dim stLinkCriteria As String
  6.  
  7.     stDocName = "MainJobForm"
  8.     DoCmd.OpenForm stDocName, , , stLinkCriteria
  9. Forms!mainjobform!.RowSourceType = "Table/Query"
  10. Forms!mainjobform!.RowSource = "qmainjobform"
  11.  
  12. Exit_Command10_Click:
  13.     Exit Sub
  14.  
  15. Err_Command10_Click:
  16.     MsgBox Err.Description
  17.     Resume Exit_Command10_Click
  18.  
  19. End Sub
Thanks in anticipation

Graeme
Jan 5 '07 #1
14 5749
MMcCarthy
14,534 Expert Mod 8TB
Hi,

Really appreciate some help with the following: ps I am very poor at VBA!

I have a form and when clicking a cmdbutton want to open the same form but with a different underlying query. I have looked some threads which just said look at Rowsource help which I have and am still none the wiser!

At the moment I have 3 forms with 3 queries and it's cumbersome obviously

In the form properties, I have removed the RecordSource data as I assume it will be populated by the VBA code

Private Sub Command10_Click()
On Error GoTo Err_Command10_Click

Dim stDocName As String
Dim stLinkCriteria As String

stDocName = "MainJobForm"
DoCmd.OpenForm stDocName, , , stLinkCriteria
Forms!mainjobform!.RowSourceType = "Table/Query"
Forms!mainjobform!.RowSource = "qmainjobform"

Exit_Command10_Click:
Exit Sub

Err_Command10_Click:
MsgBox Err.Description
Resume Exit_Command10_Click

End Sub

Thanks in anticipation

Graeme
Hi Graeme,

You cannot open a form that is currently open with a change of record source.

Mary
Jan 6 '07 #2
NeoPa
32,556 Expert Mod 16PB
Try :
Expand|Select|Wrap|Line Numbers
  1. Private Sub Command10_Click()
  2.     Me.RowSourceType = "Table/Query"
  3.     Me.RowSource = "qmainjobform"
  4. End Sub
Jan 6 '07 #3
MMcCarthy
14,534 Expert Mod 8TB
Try :
Expand|Select|Wrap|Line Numbers
  1. Private Sub Command10_Click()
  2.     Me.RowSourceType = "Table/Query"
  3.     Me.RowSource = "qmainjobform"
  4. End Sub
Guys we're mixing up Record Source and Row Source here. Record Source is the forms source whereas Row Source is used for Combo boxes and List boxes (Yes Ade, I know you already know this).

Mary
Jan 6 '07 #4
NeoPa
32,556 Expert Mod 16PB
Mary is absolutely right - that was sloppy of me.
My apologies.
I believe that the Record Source is changable from within the OnOpen event of a form (It certainly is in a report).
Try :
Expand|Select|Wrap|Line Numbers
  1. Private Sub Form_Open(Cancel As Integer)
  2.     Me.RecordSource = "qmainjobform"
  3.  
  4.     'Optionally other unrelated code
  5. End Sub
Jan 6 '07 #5
MMcCarthy
14,534 Expert Mod 8TB
Mary is absolutely right - that was sloppy of me.
Do we have to go through the Mary is ALWAYS right speech again. ;)
Jan 6 '07 #6
missinglinq
3,532 Expert 2GB
We don't HAVE to, but it's always fun!
Jan 6 '07 #7
missinglinq
3,532 Expert 2GB
I think the simple answer here is to copy the form in question, paste it, rename it when the prompt comes up, then go into Design View on the new form and change the Record Source. Then place a command button on the original form to open the new form. Should take only a couple of minutes!
Jan 6 '07 #8
MMcCarthy
14,534 Expert Mod 8TB
We don't HAVE to, but it's always fun!
OK, Repeat after me.

Mary is always right
Even when she's wrong Mary is right.


Got it?
Jan 6 '07 #9
missinglinq
3,532 Expert 2GB
As we say in Richmond (Virginia, that is) "Yes'em!"
Jan 6 '07 #10
NeoPa
32,556 Expert Mod 16PB
Mary is absolutely right - that was sloppy of me.
My apologies.
I believe that the Record Source is changable from within the OnOpen event of a form (It certainly is in a report).
Try :
Expand|Select|Wrap|Line Numbers
  1. Private Sub Form_Open(Cancel As Integer)
  2.     Me.RecordSource = "qmainjobform"
  3.  
  4.     'Optionally other unrelated code
  5. End Sub
Mary was right about that point.
That doesn't mean the code won't work - just the way I had it earlier was wrong.
Jan 8 '07 #11
leeg
14
Thanks very much everyone.

Mary was right :o)
Jan 8 '07 #12
MMcCarthy
14,534 Expert Mod 8TB
Thanks very much everyone.

Mary was right :o)
Thanks leeg.

See I told you!
Jan 8 '07 #13
NeoPa
32,556 Expert Mod 16PB
Thanks very much everyone.

Mary was right :o)
Thanks leeg.

See I told you!
Graeme she sounds mollified and safe, but believe me - she noticed you restricted that to the past tense :(
Jan 8 '07 #14
MMcCarthy
14,534 Expert Mod 8TB
Graeme she sounds mollified and safe, but believe me - she noticed you restricted that to the past tense :(
Stop trying to frighten the Newbies Ade. Let them get settled in first before you warn them about my dark side.
Jan 8 '07 #15

Sign in to post your reply or Sign up for a free account.

Similar topics

4
by: DG | last post by:
Hi, Can anyone advise how to execute multiple statements in a single query batch. For example- update customers set customer_name = 'Smith' where customer_name = 'Smyth'; select * from...
2
by: Tom Cusick | last post by:
MS Access Version 2002 (10.4302.4291) SP-2 Windows XP Pro 2002 SP-1 ----------------------------------------------------------------- Ok my question is this. I have one form laid out the way I...
4
by: intl04 | last post by:
How do I create a data input form in Access that is external to the Access database to which it's connected (if that's possible, which I believe it is)? For example, if someone clicks on an Access...
15
by: deko | last post by:
Is there a "best practices" way to run ad hoc SQL queries? Private cmdRun_Click() strSql = Me!txtBox DoCmd.RunSQL strSql End Sub ??? Does access have a built-in way to bring up a window for...
4
by: deko | last post by:
I'm a little nervous about slamming my database with a dozen Update queries in a loop that all modify RecordSources of open forms. Will the use of DoEvents and/or a Sleep function ameliorate any...
3
by: matthewemiclea | last post by:
I am trying to display information in Access on a form that takes information from many different queries and puts them together on a spreadsheet or chart. Some specific info: The information I...
10
by: glenn354 | last post by:
I have a form I would like to use in front of several queries. For example, I want to use frmA but only looking at the records retrieved by qryX. Then I want to use frmA again, but only looking at...
2
by: New2Access | last post by:
Access newbie here with what's probably a complicated question. I've been tasked with developing a simple budgeting application using MS Access for my UI. I'm not an Access developer by trade but...
3
by: CAD Fiend | last post by:
Hello, Well, after an initial review of my database by my client, they have completely changed their minds about how they want their form. As a result, I'm having to re-think the whole process....
5
by: EricS | last post by:
Hi, Was wondering if anyone can help. I have multiple queries in a database. The selection criteria for these queries is always a time period I want to do the analysis by. Rather than having to go...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.