473,413 Members | 1,794 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,413 software developers and data experts.

Change Form Record Source

mjoachim
I am trying open a form from VBA to view a record that was moved from the original table to an Archive Table. I am having a hard time changing the record source of the form to look at the Archive table instead of the original table. If I open the form first, I am able to change the record source, but am then unable to filter to the selected record since the form is already open.

Does anyone know if I am able to change the form properties before the form is open?

Here is the code that am I currently working with:
Expand|Select|Wrap|Line Numbers
  1. Public Sub RptEquipNumber_Click()
  2.  
  3.     Forms!Equipment.Form.RecordSource = "Equipment Archive"
  4.     DoCmd.OpenForm "Equipment", , , "EquipNumber ='" & RptEquipNumber & "'", acFormEdit, , SrcRcd = "Equipment Archive"
  5.  
  6. End Sub
Feb 26 '16 #1

✓ answered by NeoPa

Put code in the Form_Open() event procedure to update the RecordSource, and the Filter if necessary, of the form when it's opened.

3 6637
NeoPa
32,556 Expert Mod 16PB
Put code in the Form_Open() event procedure to update the RecordSource, and the Filter if necessary, of the form when it's opened.
Feb 28 '16 #2
Thanks for the tip. With that advice, I looked further into how to pass an argument and seem to have everything working now.

On click even from a report field:
Expand|Select|Wrap|Line Numbers
  1. Public Sub RptEquipNumber_Click()
  2.     ArEq = RptEquipNumber
  3.  
  4.     DoCmd.OpenForm "Equipment", , , , acFormReadOnly, , ArEq
  5.  
  6. End Sub
On Load event of the form using the passed argument:
Expand|Select|Wrap|Line Numbers
  1. Public Sub Form_Load()
  2.     Dim ArchEq As String
  3.     ArchEq = Nz(Me.OpenArgs, 0)
  4.  
  5.     If ArchEq > 0 Then
  6.     Forms!Equipment.Form.RecordSource = "Equipment Archive"
  7.     Me.Filter = "EquipNumber =" & ArchEq
  8.     Me.FilterOn = True
  9.     End If
  10.  
  11.     Me.EquipNumber.SetFocus
  12. End Sub
If you see any more efficient way that I should be handling this, please let me know!
Feb 29 '16 #3
NeoPa
32,556 Expert Mod 16PB
MJoachim:
Thanks for the tip. With that advice, I looked further into ...
What a perfect attitude. Lovely to see that you found your way from a small tip and have a working solution. I'm very pleased for you.
Mar 1 '16 #4

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

Similar topics

4
by: steph | last post by:
Hi, A question regarding Access 2002: I've got a form which should be displayed in Form View and in Datasheet View. But I want to use a different record source for each view. That means, when...
6
by: John | last post by:
Hi Is it possible to change the record source query of a report at runtime via code so the report can work with different data source queries? Thanks Regards
7
by: wlc04 | last post by:
I would like to be able to set the record source of a report programatically, but I am not having much luck. I have 2 queries which could be the source depending on other parameters in the program,...
1
by: wlc04 | last post by:
I would like to be able to set the record source of a report programatically, but I am not having much luck. I have 2 queries which could be the source depending on other parameters in the program,...
1
by: Whiteeagle | last post by:
Hi all I have inherated a bit of a dilema and not sure about the correct way of solving the problem. The company I work for have 60 identical but seperate databases which are all in seperate...
1
by: thread | last post by:
Hi i built a form that getting dynamic SQL string,the SQL string is placed in the record source when the form is opened. i notice when trying to reduce some proccess time from the form that it...
30
by: CD Tom | last post by:
I found Stephen Lebans modReportToPDF and have been trying to get it to work in my application. I've downloaded his database and when I run his test it works fine. I then added it to my application...
4
by: Adam Tippelt | last post by:
Situation: I'm using a continuous form to display a lot of information stored in a datasheet. I'm using the form because it allows me to display multiple rows of information per 'record' which is...
8
Teresa Kline
by: Teresa Kline | last post by:
I have a form with a combo box. In the combo box is a list of tables in my database. I want to be able to select a table from my combo box and based on that selection open another form that uses...
1
by: fspad59 | last post by:
I am using a parameterized query as the record source for an Acces form. If I run the query in Query builder it asks for the parameter value and then runs the query successfully. If I open the form...
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
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
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,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.