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

Home Posts Topics Members FAQ

Enumerate controls in a runtime environment.

Each control on my form has a number 0-9 in the TAG property. What I need
to do is to duplicate a record, but not all controls, only the ones up to
the value stored in the TAG property. It should look like.

....
Set db1 = CurrentDb()
Set rs1 = db1.OpenRecordset("tblLang")

DoCmd.OpenForm "MyForm", acDesign
Set frm = forms("MyForm")

rs1.AddNew

For Each ctl In frm.Controls

If ctl.tag <=TAG_VALUE

rs1!ctl.controlsource = ctl.value 'not sure about this one
rs1.Update
rs1.Bookmark = rs1.LastModified

end if

Next ctl
....

But opening a form in acDesign mode won't work in a runtime environment,
right? What are my options? TIA.
Nov 13 '05 #1
3 1906
This example duplicates the current record in the form, by copying it to the
form's RecordsetClone. It assumes that any of the contorls that have a
number in their Tag property are controls that are bound directly to a
field.

Dim rs As DAO.Recordset
Dim ctl As Control
Dim strField As String

If Me.Dirty Then 'Save first
Me.Dirty = False
End If
If Me.NewRecord Then 'Make sure there is a record.
MsgBox "Select a record to duplicate"
Else
'Duplicate to the form's clone set
Set rs = Me.RecordsetClone
rs.AddNew
For Each ctl In Me.Contorls
If IsNumeric(ctl.Tag) Then
strField = ctl.ControlSource
rs(strField) = ctl.Value
End If
Next
rs.Update
'Make that record the current one.
Me.Bookmark = rs.LastModified
End If

Set rs = Nothing

--
Allen Browne - Microsoft MVP. Perth, Western Australia.
Tips for Access users - http://allenbrowne.com/tips.html
Reply to group, rather than allenbrowne at mvps dot org.

"Saintor" <sa******@REMOVETHIShotmail.com> wrote in message
news:Fx********************@weber.videotron.net...
Each control on my form has a number 0-9 in the TAG property. What I need
to do is to duplicate a record, but not all controls, only the ones up to
the value stored in the TAG property. It should look like.

...
Set db1 = CurrentDb()
Set rs1 = db1.OpenRecordset("tblLang")

DoCmd.OpenForm "MyForm", acDesign
Set frm = forms("MyForm")

rs1.AddNew

For Each ctl In frm.Controls

If ctl.tag <=TAG_VALUE

rs1!ctl.controlsource = ctl.value 'not sure about this one
rs1.Update
rs1.Bookmark = rs1.LastModified

end if

Next ctl
...

But opening a form in acDesign mode won't work in a runtime environment,
right? What are my options? TIA.

Nov 13 '05 #2
You don't have to open a form in design mode to set tag properties of controls
at run-time, the changes simply don't get saved when changed at run-time.
Usually, that's exactly what you want. If you need to persist the data,
tables are the best way to do it in Access, obviously.

On Fri, 2 Jul 2004 10:44:16 -0400, "Saintor" <sa******@REMOVETHIShotmail.com>
wrote:
Each control on my form has a number 0-9 in the TAG property. What I need
to do is to duplicate a record, but not all controls, only the ones up to
the value stored in the TAG property. It should look like.

...
Set db1 = CurrentDb()
Set rs1 = db1.OpenRecordset("tblLang")

DoCmd.OpenForm "MyForm", acDesign
Set frm = forms("MyForm")

rs1.AddNew

For Each ctl In frm.Controls

If ctl.tag <=TAG_VALUE

rs1!ctl.controlsource = ctl.value 'not sure about this one
rs1.Update
rs1.Bookmark = rs1.LastModified

end if

Next ctl
...

But opening a form in acDesign mode won't work in a runtime environment,
right? What are my options? TIA.


Nov 13 '05 #3
Thanks a lot. It works.

"Allen Browne" <Al*********@SeeSig.Invalid> wrote in message news:<40***********************@per-qv1-newsreader-01.iinet.net.au>...
This example duplicates the current record in the form, by copying it to the
form's RecordsetClone. It assumes that any of the contorls that have a
number in their Tag property are controls that are bound directly to a
field.

Dim rs As DAO.Recordset
Dim ctl As Control
Dim strField As String

If Me.Dirty Then 'Save first
Me.Dirty = False
End If
If Me.NewRecord Then 'Make sure there is a record.
MsgBox "Select a record to duplicate"
Else
'Duplicate to the form's clone set
Set rs = Me.RecordsetClone
rs.AddNew
For Each ctl In Me.Contorls
If IsNumeric(ctl.Tag) Then
strField = ctl.ControlSource
rs(strField) = ctl.Value
End If
Next
rs.Update
'Make that record the current one.
Me.Bookmark = rs.LastModified
End If

Set rs = Nothing

--
Allen Browne - Microsoft MVP. Perth, Western Australia.
Tips for Access users - http://allenbrowne.com/tips.html
Reply to group, rather than allenbrowne at mvps dot org.

Nov 13 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
3574
by: Mathew | last post by:
Hi How do you specfiy the version of the .net runtime libraries loaded for a ..net controls hosted in Internet Explorer 6? I have a control that's designed to work with .NET 1.1, but after...
3
1541
by: Paul Watson | last post by:
I see the list of standard encodings in Python 2.4.1 documentation section 4.9.2. Is there a method to enumerate the registered codecs at runtime?
1
5147
by: Mike | last post by:
Hi Hi We are currently upgrading from access 97 to office 2003 on site. We would like to upgrade our access databases to Access 2003 but we wish to remove Microsoft access software from our end...
3
2303
by: Cliff Harris | last post by:
I have an odd question that I'm hoping someone can help with. I simply (or not simply?) need to enumerate through all of the data types in the .Net framework. I do understand that if this is...
1
4554
by: MuZZy | last post by:
Hi, I need to build a function which would return all controls which are upper in z-order relatively to given control. I need this in order to be able to temporary bring the control to front...
5
6953
by: HL | last post by:
Hi, I need to enumerate windows and find the sum of the rect of all the windows of a specific application. In C++, I use the APIs - 'EnumWindows , GetWindowRect and UnionRect to accomplish the...
2
2246
by: Tym | last post by:
I was looking for a way to add a control array at runtime - but it doesn't look like vb.net has that ability any more... Was looking at controls one at a time thus: Dim Label1 As New Label...
2
1052
by: ngr | last post by:
I am using VB2005 Enterprise after migrating from 2003 Enterprise. In the design environment, the buttons have Xp style rounded buttons and frames but when I run in the runtime environment the...
3
1669
by: Mike Collins | last post by:
I have some controls that I am creating dynamically. After the user finishes entering their answers in these controls, I would like to iterate through these controls and get the answers out. I have...
0
7084
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
7278
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
7328
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...
1
6991
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
7458
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
3167
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
3154
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1512
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
736
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.