Hi,
I was just curious if there was anyway to change permanently the recordsource for a form? Specifically, I used the CopyObject method to create a new form based off an existing form. Now I want the new form to have a new recordsource different from the recordsource of the copied form.
6 3571
Hi,
I was just curious if there was anyway to change permanently the recordsource for a form? Specifically, I used the CopyObject method to create a new form based off an existing form. Now I want the new form to have a new recordsource different from the recordsource of the copied form.
After copying you could open in design change the recordsource and then save the form on close obviously amend this to suit your object names. -
-
DoCmd.CopyObject "", "YourNewformname", acForm, "CopiedFromFormName"
-
DoCmd.OpenForm "YourNewFormName", acDesign, , , , acHidden
-
Forms!YourNewFormName.RecordSource = "Select * from YourTableName"
-
DoCmd.Close acForm, "YourNewFormName", acSaveYes
-
Jim :)
After copying you could open in design change the recordsource and then save the form on close obviously amend this to suit your object names. -
-
DoCmd.CopyObject "", "YourNewformname", acForm, "CopiedFromFormName"
-
DoCmd.OpenForm "YourNewFormName", acDesign, , , , acHidden
-
Forms!YourNewFormName.RecordSource = "Select * from YourTableName"
-
DoCmd.Close acForm, "YourNewFormName", acSaveYes
-
Jim :)
What if my newform name is dynamic, i.e. I use a variable to refer to the form? I always have trouble with the quotes and syntaxing. For example, how do I correctly do this command: Forms!YourNewFo rmName.Recordso urce with a variable representing the form?
Thanks!
What if my newform name is dynamic, i.e. I use a variable to refer to the form? I always have trouble with the quotes and syntaxing. For example, how do I correctly do this command: Forms!YourNewFo rmName.Recordso urce with a variable representing the form?
Thanks!
If we assume that you have just used the copyobject command to create your new form then it will exist as a named object, therefore the following code will open that form in design and instead of saving on close without prompt, it will show it to you with the amendment to the recordsource.
Obviously the form name here is called Form1 but you will know what the name of your form is you are copying into so just replace "Form1" here with the name of your newly created form. If this is not what you mean then post your code and lets see the context in which you are programming. - Dim strFormName As String
-
strFormName = "Form1"
-
Dim frm As Access.Form
-
DoCmd.OpenForm strFormName, acDesign
-
Set frm = Forms!Form1
-
' Set form properties.
-
With frm
-
.RecordSource = "SELECT * FROM MyTable"
-
End With
-
Jim :)
If we assume that you have just used the copyobject command to create your new form then it will exist as a named object, therefore the following code will open that form in design and instead of saving on close without prompt, it will show it to you with the amendment to the recordsource.
Obviously the form name here is called Form1 but you will know what the name of your form is you are copying into so just replace "Form1" here with the name of your newly created form. If this is not what you mean then post your code and lets see the context in which you are programming. - Dim strFormName As String
-
strFormName = "Form1"
-
Dim frm As Access.Form
-
DoCmd.OpenForm strFormName, acDesign
-
Set frm = Forms!Form1
-
' Set form properties.
-
With frm
-
.RecordSource = "SELECT * FROM MyTable"
-
End With
-
Jim :)
I'm not sure I'm understanding you...Here is my code and what I want to do with it.
[code]
Dim NewName As String
Dim Concatnewfrm As String
NewName = Me.NewEquiplist .Value
Concatnewfrm = "frm_" & NewName
DoCmd.CopyObjec t , NewName, acTable, "Standard"
DoCmd.CopyObjec t , Concatnewfrm, acForm, "frm_Standa rd2"
[code]
Here is the context/situation:
On the working form, the user types in the name of a new list. The control where this is typed into is called NewEquiplist. Upon clicking a command button, I hope to create a new table based on the "Standard" table with the name the user just typed in. Then, I would like to create a form based on "frm_Standa rd2" but with its recordsource changed to the new table i just created.
Thanks
I'm not sure I'm understanding you...Here is my code and what I want to do with it.
[code]
Dim NewName As String
Dim Concatnewfrm As String
NewName = Me.NewEquiplist .Value
Concatnewfrm = "frm_" & NewName
DoCmd.CopyObjec t , NewName, acTable, "Standard"
DoCmd.CopyObjec t , Concatnewfrm, acForm, "frm_Standa rd2"
[code]
Here is the context/situation:
On the working form, the user types in the name of a new list. The control where this is typed into is called NewEquiplist. Upon clicking a command button, I hope to create a new table based on the "Standard" table with the name the user just typed in. Then, I would like to create a form based on "frm_Standa rd2" but with its recordsource changed to the new table i just created.
Thanks
OK the reason I asked for the context of this is because you mentioned referring to a form using a variable. I see that you are relatively new to Access so I assumed you might not know the differences technically. A variable has different meanings in different situations.
Now looking at your code I can see that yes....you are using a variable...but only in the sense that it is a string variable referring to the 'name' of the form rather than the form itself as an object reference. There is a subtle difference.
I have no idea what your overall design strategy is in doing what you are doing by copying existing objects into more objects I am curious as to the reasoning behind it.
Going with your strategy as it is:
When you do create extra objects you have to consider how you control that scenario. A simple command of 'Docmd Copyobject' does what it says on the tin so to speak...but..wh at happens if it doesnt, what happens if the object is already in place or if the user types invalid character into the textbox or too many perhaps. The program flow errors and so on.
You can try to perceive the obvious problems that might be encountered during a program flow trap for those and for those that you cannot ? ...well it errors out and you debug to track any causes etc.
The following code is a reshape of that which you have seen thus far. Now that I have seen your code context I can give you something back to chew over and maybe you might see things in there that are relevant to you. I have included in it error handling to sit within the on click event procedure of a control (command button) called command1
I have attached the code logic in a text file mainly because the messaging on here is truncating my replies to this thread tonight.
Regards
Jim :)
OK the reason I asked for the context of this is because you mentioned referring to a form using a variable. I see that you are relatively new to Access so I assumed you might not know the differences technically. A variable has different meanings in different situations.
Now looking at your code I can see that yes....you are using a variable...but only in the sense that it is a string variable referring to the 'name' of the form rather than the form itself as an object reference. There is a subtle difference.
I have no idea what your overall design strategy is in doing what you are doing by copying existing objects into more objects I am curious as to the reasoning behind it.
Going with your strategy as it is:
When you do create extra objects you have to consider how you control that scenario. A simple command of 'Docmd Copyobject' does what it says on the tin so to speak...but..wh at happens if it doesnt, what happens if the object is already in place or if the user types invalid character into the textbox or too many perhaps. The program flow errors and so on.
You can try to perceive the obvious problems that might be encountered during a program flow trap for those and for those that you cannot ? ...well it errors out and you debug to track any causes etc.
The following code is a reshape of that which you have seen thus far. Now that I have seen your code context I can give you something back to chew over and maybe you might see things in there that are relevant to you. I have included in it error handling to sit within the on click event procedure of a control (command button) called command1
I have attached the code logic in a text file mainly because the messaging on here is truncating my replies to this thread tonight.
Regards
Jim :)
Thanks so much for your help, Jim. That was great.
Sign in to post your reply or Sign up for a free account.
Similar topics |
by: lauren quantrell |
last post by:
When I open an Access form I can have no recordset specified, then in
the form's OnOpen event I can do something like:
Me.paramaters = "@SomeColumn = 22)"
Me.recordsource = "dbo.sproc123"
But I can't do this in a report as it will prompt me for the
parameters, even though they seem to be defined ahead of the
recordsource.
I have worked around this by opening reports to a bogus recordsource
|
by: thomas.jacobs |
last post by:
I have reports formated and now need to use that format on another
table name with the same field names as formated in the report.
I belive it is in the properties but I can't seem to find it.
thanks
|
by: OldBirdman |
last post by:
On a Report, can I change any of the fields in the "Sorting and Grouping Dialog" from within Visual Basic??? Changing the OrderBy property of the Report doesn't change anything, nor does adding an "ORDER BY" clause to the RecordSource SQL Statement.
I have a table, named tInventory. It contains a text field called Item. There may be more than one row where Item is duplicated. I use a field called Year to distinguish them on the printed...
|
by: Simon |
last post by:
Dear reader,
The syntax for the VBA code to change the RowSource of a Form is:
Forms!FormName..RowSource = "TableOrQueryName"
|
by: Simon |
last post by:
Dear reader,
The syntax for the VBA code to change the RowSource of a Master Report is:
Me.RowSource = "TableOrQueryName"
| |
by: David Haskins |
last post by:
I have a fairly complex interface screen (form) that is comprised of
several subforms that perform different, but related activities. I am
designing a search/filter form that should be able to change the data
displayed in one or more of the other forms, but I cannot find the way
to change the Recordsource property of the second form from the first.
In a VBA Sub procedure triggered by the Click event of a button on the
search form, I...
|
by: Rich P |
last post by:
I'm not sure if you can change the recordsource of a form that currently
has the focus. I will be in a mainform where I can change the
recordsoure of a subform. The big thing is to remember to reset the
control source for each textbox in the subform (or mainform if it is
possible to change the recordsource from within the mainform). When you
change the recordsource - you have to re-point each textbox to the
desired control source.
...
|
by: Simon |
last post by:
Dear reader,
The syntax for the VBA code to change the RecordSource of a Master Report
is:
Me.RecordSource = "TableOrQueryName"
|
by: agarwasa2008 |
last post by:
Hi,
I have a linked table called tbltest and some bounded forms (which
add, update, delete records) that were created using that linked
table. For some necessary reasons I had to create another linked table
called tblComponents and then I bounded the original forms to this new
table. I did change the
control source: Description (Field name)
RowSource Type: Table/Query (which remains the same)
|
by: Simon van Beek |
last post by:
Dear reader,
How to change the RecordSource for a subReport.
For forms the syntaxes is:
|
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
| |
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
| |
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |