473,503 Members | 1,768 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Change RecordSource

7 New Member
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.
Dec 12 '07 #1
6 3560
Jim Doherty
897 Recognized Expert Contributor
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.

Expand|Select|Wrap|Line Numbers
  1.  
  2.     DoCmd.CopyObject "", "YourNewformname", acForm, "CopiedFromFormName"
  3.     DoCmd.OpenForm "YourNewFormName", acDesign, , , , acHidden
  4.     Forms!YourNewFormName.RecordSource = "Select * from YourTableName"
  5.     DoCmd.Close acForm, "YourNewFormName", acSaveYes
  6.  
Jim :)
Dec 12 '07 #2
jcethiopia
7 New Member
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.

Expand|Select|Wrap|Line Numbers
  1.  
  2.     DoCmd.CopyObject "", "YourNewformname", acForm, "CopiedFromFormName"
  3.     DoCmd.OpenForm "YourNewFormName", acDesign, , , , acHidden
  4.     Forms!YourNewFormName.RecordSource = "Select * from YourTableName"
  5.     DoCmd.Close acForm, "YourNewFormName", acSaveYes
  6.  
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!YourNewFormName.Recordsource with a variable representing the form?

Thanks!
Dec 12 '07 #3
Jim Doherty
897 Recognized Expert Contributor
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!YourNewFormName.Recordsource 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.

Expand|Select|Wrap|Line Numbers
  1.  Dim strFormName As String
  2. strFormName = "Form1" 
  3. Dim frm As Access.Form
  4. DoCmd.OpenForm strFormName, acDesign
  5.     Set frm = Forms!Form1
  6.     ' Set form properties.
  7.     With frm
  8.         .RecordSource = "SELECT * FROM MyTable"
  9.     End With
  10.  
Jim :)
Dec 12 '07 #4
jcethiopia
7 New Member
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.

Expand|Select|Wrap|Line Numbers
  1.  Dim strFormName As String
  2. strFormName = "Form1" 
  3. Dim frm As Access.Form
  4. DoCmd.OpenForm strFormName, acDesign
  5.     Set frm = Forms!Form1
  6.     ' Set form properties.
  7.     With frm
  8.         .RecordSource = "SELECT * FROM MyTable"
  9.     End With
  10.  
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.CopyObject , NewName, acTable, "Standard"
DoCmd.CopyObject , Concatnewfrm, acForm, "frm_Standard2"
[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_Standard2" but with its recordsource changed to the new table i just created.

Thanks
Dec 12 '07 #5
Jim Doherty
897 Recognized Expert Contributor
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.CopyObject , NewName, acTable, "Standard"
DoCmd.CopyObject , Concatnewfrm, acForm, "frm_Standard2"
[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_Standard2" 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..what 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 :)
Attached Files
File Type: txt command1.txt (5.7 KB, 404 views)
Dec 13 '07 #6
jcethiopia
7 New Member
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..what 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.
Dec 13 '07 #7

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

Similar topics

8
10731
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...
6
6144
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....
10
7549
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...
8
23743
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"
11
7432
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"
2
3467
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...
0
1654
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...
3
9367
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"
5
1971
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...
3
10653
by: Simon van Beek | last post by:
Dear reader, How to change the RecordSource for a subReport. For forms the syntaxes is:
0
7199
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7274
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
7323
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
7453
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...
1
5005
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...
0
4670
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...
0
3162
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...
0
1507
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
732
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.