473,595 Members | 2,474 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Subform Navigation

I am trying to create global code for navigation use in all my forms --
including subforms. I searched, and searched, but can not find how to
globally reference a subform object. I need to have the navigation
buttons on the subform itself, but I would like to code to be global so
I can reuse it in my many subforms.
>From what I understand, a subform can't be referenced as an open form,
but only as a control in the partent form. So how can I change records
in a control?

I have tried to reference the subform every way I could think of, or
could find here or in help:

Forms![frmMyParentForm]![ctrlMySubFormOb ject].Form
Forms![frmMyParentForm]![ctrlMySubFormOb ject].SourceObject

I have also tried doing this via a string for the form name, and using
the form object. I think I would rather use the form object, as I would
also like to do some other things beside change records (enable/disable
buttons, ext)

Can someone help me here, or point me to some more info? Thanks in
advance.

Jeff Smeker

Nov 17 '06 #1
14 4027
Pass the Me reference to the function/sub.

Public Sub MoveToNext(curr entRecordId As Long, frm As Form)
{Your code here}
Ends Sub

Call it from a form or subform:

MoveToNext Me.txtId, Me

Of course, writing the code to do what you want may still be tricky.

I used this as a global listbox refresh for forms and subforms
=============== ==========
Public Sub List_Refresh(id As String, frm As Form, _
Optional move_cursor = 0)
Dim rsc As Object
Dim lst As ListBox
Set rsc = frm.Recordset.C lone
Set lst = frm!lstRecords
lst.Requery
If rsc.RecordCount <= 0 Then
Set lst = Nothing
Exit Sub
End If

If move_cursor = NEW_ITEM Then
rsc.MoveLast
frm.Bookmark = rsc.Bookmark
lst.Value = frm!txtId
Else
If move_cursor = LAST_ITEM Then
lst.Value = lst.ItemData(ls t.ListCount - 1)
Else
If IsNull(lst.Valu e) Or move_cursor = TOP_ITEM Then
If lst.ColumnHeads Then
lst.Value = lst.ItemData(1)
Else
lst.Value = lst.ItemData(0)
End If
End If
End If
If Not IsNull(lst.Valu e) Then
rsc.Findfirst id & "=" & lst.Value
If Not rsc.EOF Then frm.Bookmark = rsc.Bookmark
End If
End If
Set lst = Nothing
End Sub
--
Darryl Kerkeslager

"Rational Repairs" <ra************ *@gmail.comwrot e
>I am trying to create global code for navigation use in all my forms --
including subforms. I searched, and searched, but can not find how to
globally reference a subform object. I need to have the navigation
buttons on the subform itself, but I would like to code to be global so
I can reuse it in my many subforms.

Nov 18 '06 #2
Thanks for the tip. I should have mentioned, I tried passing the Me
reference. The problem is that I receive errors saying the specific
subform isn't open. I think that when a form is being used as a
subform, is not *really* open (meaning it's not found in the forms
collection), so it can't be referenced that way.

Even in your code example below, passing Me from a subform wound't
work. Unless I'm completely missing something here. Wouldn't be the
first time!

If a subform isn't an open form, how the heck do you work with it
globally via VB?

Thanks again.

Darryl Kerkeslager wrote:
Pass the Me reference to the function/sub.

Public Sub MoveToNext(curr entRecordId As Long, frm As Form)
{Your code here}
Ends Sub

Call it from a form or subform:

MoveToNext Me.txtId, Me

Of course, writing the code to do what you want may still be tricky.

I used this as a global listbox refresh for forms and subforms
=============== ==========
Public Sub List_Refresh(id As String, frm As Form, _
Optional move_cursor = 0)
Dim rsc As Object
Dim lst As ListBox
Set rsc = frm.Recordset.C lone
Set lst = frm!lstRecords
lst.Requery
If rsc.RecordCount <= 0 Then
Set lst = Nothing
Exit Sub
End If

If move_cursor = NEW_ITEM Then
rsc.MoveLast
frm.Bookmark = rsc.Bookmark
lst.Value = frm!txtId
Else
If move_cursor = LAST_ITEM Then
lst.Value = lst.ItemData(ls t.ListCount - 1)
Else
If IsNull(lst.Valu e) Or move_cursor = TOP_ITEM Then
If lst.ColumnHeads Then
lst.Value = lst.ItemData(1)
Else
lst.Value = lst.ItemData(0)
End If
End If
End If
If Not IsNull(lst.Valu e) Then
rsc.Findfirst id & "=" & lst.Value
If Not rsc.EOF Then frm.Bookmark = rsc.Bookmark
End If
End If
Set lst = Nothing
End Sub
--
Darryl Kerkeslager

"Rational Repairs" <ra************ *@gmail.comwrot e
I am trying to create global code for navigation use in all my forms --
including subforms. I searched, and searched, but can not find how to
globally reference a subform object. I need to have the navigation
buttons on the subform itself, but I would like to code to be global so
I can reuse it in my many subforms.
Nov 18 '06 #3
The subform is really open (you can run code in the open event to test
this). While the subform is not added to the Forms collection, that doesn't
mean it's not open - it still can be referenced as a form by using Me. That
is why from the subform, you can use code such as

MsgBox Me.txtString

but not

MsgBox Forms("TheSubfo rm").txtStrin g
Even in your code example below, passing Me from a subform wouldn't
work.
But it does, otherwise I wouldn't have posted it.

Perhaps, at the time you called the function passing in Me as a form
reference, the subform was in fact not open?
--
Darryl Kerkeslager
Nov 18 '06 #4
Rational Repairs wrote:
Thanks for the tip. I should have mentioned, I tried passing the Me
reference. The problem is that I receive errors saying the specific
subform isn't open. I think that when a form is being used as a
subform, is not *really* open (meaning it's not found in the forms
collection), so it can't be referenced that way.
If the form has a code module, or the HasModule property set to True it
can be referenced from anywhere with
Form_FormName
that is if the sub form is named OrderDetails then
Form_OrderDetai ls
points to the form, whether or not it's being used as a subform
and
Form_OrderDetai ls.Property
Form_OrderDetai ls.Function
Form_OrderDetai ls.Sub
Form_OrderDetai ls.Control
are all valid for Public procedures and controls.

Nov 18 '06 #5
I guess I should not have said your code example wound't work before
testing it.

But, it appears various methods work differently. For example:

Dim frmForm as Form
Set frmForm = 'form being passed to function
DoCmd.GoToRecor d acForm, frmForm, , acNext

Received the "form not open" error (The button used to initiate the
function is on the form in question. So it was open)...

....but

frmForm.Records et.RecordCount

Works like a champ.

I did find that this, instead, will work to change the record:
DoCmd.GoToRecor d acActiveDataObj ect, , acNext

This works but relies on the subform having the focus. Being that the
buttons are located on the subform *I guess* that will always be the
case. Doesn't seem right though.

Am I thinking correctly here?
Darryl Kerkeslager wrote:
The subform is really open (you can run code in the open event to test
this). While the subform is not added to the Forms collection, that doesn't
mean it's not open - it still can be referenced as a form by using Me. That
is why from the subform, you can use code such as

MsgBox Me.txtString

but not

MsgBox Forms("TheSubfo rm").txtStrin g
Even in your code example below, passing Me from a subform wouldn't
work.

But it does, otherwise I wouldn't have posted it.

Perhaps, at the time you called the function passing in Me as a form
reference, the subform was in fact not open?
--
Darryl Kerkeslager
Nov 18 '06 #6
Your original post said:
>I searched, and searched, but can not find
how to globally reference a subform object
You now have two methods: pass the Me reference to a function, or Lyle has
also posted a method that I was unaware of.

Re-reading you original post, I see:
>I think I would rather use the form object, as I would
also like to do some other things beside change records
(enable/disable buttons, ext)
IMHO, it is far easier to enable/disable controls in code used in the
form/subform's module, most importantly because you can use the Me reference

Me!txtID

without having to refer to the subform

Me!boxPeskySubF orm.Form.txtID

or using the forms collection

Forms("MainForm ").boxPeskySubF orm.Form.txtID

Me also tends to be a marginally quicker way to reference the control, and
probably more so if you have to call a function.

I would say the same for using global code to navigate the form. What you
gain in modular coding, you are losing in simplicity (and maybe speed).

--
Darryl Kerkeslager
Nov 18 '06 #7
"Darryl Kerkeslager" <ke*********@co mcast.netwrote in
news:Ic******** *************** *******@comcast .com:
Pass the Me reference to the function/sub.

Public Sub MoveToNext(curr entRecordId As Long, frm As Form)
{Your code here}
Ends Sub
I would define that ByVal so as not to create an implicit reference
to the control passed to the first argument.
Call it from a form or subform:

MoveToNext Me.txtId, Me

Of course, writing the code to do what you want may still be
tricky.

I used this as a global listbox refresh for forms and subforms
============== ===========
Public Sub List_Refresh(id As String, frm As Form, _
Optional move_cursor = 0)
Dim rsc As Object
Dim lst As ListBox
Set rsc = frm.Recordset.C lone
Er, why not frm.RecordsetCl one? That will work in all versions of
Access, where frm.Recordset.C lone will work only from A2K on.

--
David W. Fenton http://www.dfenton.com/
usenet at dfenton dot com http://www.dfenton.com/DFA/
Nov 18 '06 #8
"Rational Repairs" <ra************ *@gmail.comwrot e in
news:11******** **************@ f16g2000cwb.goo glegroups.com:
But, it appears various methods work differently. For example:

Dim frmForm as Form
Set frmForm = 'form being passed to function
DoCmd.GoToRecor d acForm, frmForm, , acNext

Received the "form not open" error (The button used to initiate
the function is on the form in question. So it was open)...
DoCmd form operations are not needed. All you need to do to navigate
records is to use bookmark navigation, using the subform's
RecordsetClone, as outlined in the code Darryl posted.

Seems to me that nobody but novices uses DoCmd.GoToRecor d for plain
old record navigation, whether in parent forms or child forms.

--
David W. Fenton http://www.dfenton.com/
usenet at dfenton dot com http://www.dfenton.com/DFA/
Nov 18 '06 #9
"David W. Fenton" <XX*******@dfen ton.com.invalid wrote
Er, why not frm.RecordsetCl one? That will work in all versions of
Access, where frm.Recordset.C lone will work only from A2K on.
I began programming in Access in 2001. Although I've had to use and open 97
databases, I've never had to write to one.

I've heard rumors that there were versions even before 97, but I've never
actually seen them, so I doubt that they really exist.
--
Darryl Kerkeslager
Nov 19 '06 #10

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

Similar topics

2
8072
by: Mark B | last post by:
I have a form with a subform (normal) that itself has a subform (datasheet). I can't get a delete command button to work with the following code. It says "delete not available now". Any suggestions? '***************************************************************** Public Function DeleteRecord() Dim frm As Form, subfrm As Form
0
8390
by: Carl | last post by:
I have a main form with navigation buttons on it and a label showing for example Record 1 of 15 using recordsetclone on it and eveything works fine. When I move through the records the record number changes fine. Within this main form I have a subform detailing distribution records for the contact (main form is based on this) that also has navigation buttons and a label showing Distribution 1 of ##. This is where the problem lies. The...
1
3727
by: xmp333 | last post by:
Hi, I have a form that is designed as a data sheet view. Attached to this is a subform with some VB code. When the user clicks on a row, the subform should pop up and run the VB code which accesses the record corresponding to the row clicked. To get this row, I tried using Me.Parent.Bookmark. Unfortunately, this gets the "Current Record" which is set via the navigation
1
1620
by: (Pete Cresswell) | last post by:
I'm using a subform as a navigation list. On the left side of the screen is a subform containing people's names. The right side of the screen is loaded with information about the currently-selected person. As the user walks the list, the right side of the screen gets reloaded with info about each new name. When the user decides to change something, they click an "Edit" button that puts
10
3610
by: Thelma Lubkin | last post by:
My form/subform combination that allows user to display 'ColorSet' records, move to other records via a selector, to add,delete, and edit them, and to manage the related 'Color' records from the subform is close to completion, but I still need help... The parent form's recordset has fields string integer COLORNAME CLASSSIZE and a few more that aren't relevant here.
1
3063
by: planetthoughtful | last post by:
Hi All, I have a mainform with a subform in which I show some task summary data. On the mainform I have a number of unbound controls that reflect values relevant to each task in the subform. The unbound controls are populated in the subform's OnCurrent even from a number of different tables related to the records in tbl_tasks, which is the recordset displayed in the subform.
1
4248
by: RLC603 | last post by:
I have a form with subform which details documents within a contract and data elements within the documents. The form contains info. about the contract and one or several documents associated with the contract based on section_id. The form displays only one document at a time. The subform contains data elements associated with a contracts documents based on section_id. Using the form navigation bar, or code associated with a...
6
7982
by: MarkoBBC | last post by:
Hi everyone, First a brief description of my form: I have a subform within a main form. In my subform, I have a listbox displaying address information by firm name. A user first has to select a firm name in a combo box above the list box. The listbox and the combo box join on firm name. The listbox records what address was selected in the address table by the way of an address id number. I set up a macro to requery the listbox when you...
4
2899
by: virtualgreek | last post by:
Dear All, First of all I would like to take the time to thank you all for your efforts and time spent at this wonderful forum. I have found it very helpful with numerous examples available for every level of user. I am facing a rather weird behaviour with a combo box on a subform (Continuous form). I have two tables. Order and Order_Details. The master form is based on the Orders tables and the details form (subform) is based on the...
0
7955
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
7883
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8261
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, 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...
1
8019
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8251
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 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...
0
5418
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();...
0
3873
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...
1
1490
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
1223
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.