子窗体导航 [英] Subform Navigation

查看:90
本文介绍了子窗体导航的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在我的所有表单中创建用于导航的全局代码 -

包括子表单。我搜索并搜索,但找不到如何全局引用子表单对象。我需要在子窗体上有导航

按钮,但是我想编码为全局,所以

我可以在我的很多子窗体中重复使用它。


>根据我的理解,子表单不能作为开放表单引用,



但是仅作为部分形式的控件。那么如何在控件中更改记录



我试图以我能想到的每一种方式引用子表单,或者

可以在这里或在帮助中找到:


Forms![frmMyParentForm]![ctrlMySubFormObject] .Form

Forms![frmMyParentForm]![ctrlMySubFormObject] .SourceObject


我也试过通过表单名称的字符串,并使用

表单对象。我想我宁愿使用表单对象,因为我会在改变记录旁边做一些其他事情(启用/禁用

按钮,分机)


有人可以帮助我,或者给我一些更多信息吗?谢谢

预付款。


Jeff Smeker

解决方案

将Me引用传递给函数/ sub。


Public Sub MoveToNext(currentRecordId As Long,frm As Form)

{Your code here}

结束子


从表格或子表单中调用它:


MoveToNext Me.txtId,Me


当然,编写代码来做你想做的事情可能仍然很棘手。


我用它作为表单和子表单的全局列表框刷新/>
=========================

Public Sub List_Refresh(id as String,frm As Form ,_

可选move_cursor = 0)

Dim rsc As Object

Dim lst作为ListBox

设置rsc = frm.Recordset.Clone

设置lst = frm!lstRecords

lst.Requery

如果rsc.RecordCount< = 0那么

设置lst = Nothing

退出Sub

结束如果


如果move_cursor = NEW_I TEM然后

rsc.MoveLast

frm.Bookmark = rsc.Bookmark

lst.Value = frm!txtId

Else

如果move_cursor = LAST_ITEM那么

lst.Value = lst.ItemData(lst.ListCount - 1)

Else

如果是IsNull(lst.Value)或者move_cursor = TOP_ITEM那么

如果是lst.ColumnHeads那么

lst.Value = lst.ItemData(1)

Else

lst.Value = lst.ItemData(0)

结束如果

结束如果

结束如果

如果不是IsNull(lst.Value)那么

rsc.Findfirst id& " =" &安培; lst.Value

如果不是rsc.EOF那么frm.Bookmark = rsc.Bookmark

结束如果

结束如果

Set lst = Nothing

End Sub

-

Darryl Kerkeslager


"理性修复 < ra ************* @ gmail.comwrote


>我正在尝试创建所有导航使用的全局代码我的表格 -

包括子表格。我搜索并搜索,但找不到如何全局引用子表单对象。我需要在子窗体上有导航

按钮,但是我想编码为全局,所以

我可以在我的很多子窗体中重复使用它。



感谢您的提示。我应该提到,我试过通过我

参考。问题是我收到错误,说具体的

子表单没有打开。我认为当一个表单被用作

子表单时,不是*真的*打开(意味着它没有在表单中找到

集合),所以它不能被这样引用。


即使在下面的代码示例中,将我从子表单中传递出去也不会工作。除非我在这里完全遗漏了什么。不是第一次的




如果一个子表单不是一个开放的表单,你怎么用它呢?br />
全球通过VB?


再次感谢。


Darryl Kerkeslager写道:


将Me引用传递给函数/ sub。


Public Sub MoveToNext(currentRecordId As Long,frm As Form)

{你的代码在这里}

结束Sub


从表格或子表单中调用它:


MoveToNext Me.txtId ,我


当然,编写代码来做你想做的事可能仍然很棘手。


我用它作为全局列表框刷新表格和子表格

=========================

Public Sub List_Refresh(id作为String,frm As Form,_

可选move_cursor = 0)

Dim rsc As Object

Dim lst作为ListBox

设置rsc = frm.Recordset.Clone

设置lst = frm!lstRecords

lst.Requery

如果rsc.RecordCount< = 0那么

设置lst =没有什么

退出Sub

结束如果


如果move_cursor = NEW_ITEM那么

rsc.MoveLast

frm.Bookmark = rsc.Bookmark

lst.Value = frm!txtId

Else

如果move_cursor = LAST_ITEM然后

lst.Value = lst.ItemData(lst.ListCount - 1)

否则

如果IsNull(lst.Value)或move_cursor = TOP_ITEM然后

如果是lst.ColumnHeads那么

lst.Value = lst.ItemData(1)

Else

lst.Value = lst.ItemData(0)

结束如果

结束如果

结束如果

如果不是IsNull(lst.Value)那么

rsc.Findfirst id& " =" &安培; lst.Value

如果不是rsc.EOF那么frm.Bookmark = rsc.Bookmark

结束如果

结束如果

Set lst = Nothing

End Sub


-

Darryl Kerkeslager


Rational Repairs < ra ************* @ gmail.comwrote


我正在尝试在我的所有表单中创建导航使用的全局代码 -

包括子表格。我搜索并搜索,但找不到如何全局引用子表单对象。我需要在子窗体上有导航

按钮,但我希​​望编码为全局代码

我可以在我的许多子窗体中重用它。


子窗体真的是开放的(你可以在open事件中运行代码来测试

这个)。虽然子窗体没有添加到Forms集合中,但是没有b $ b意味着它没有打开 - 它仍然可以通过使用Me作为表单引用。那个

是为什么从子表单中,你可以使用代码如


MsgBox Me.txtString


但是不是

MsgBox表格(TheSubform)。txtString


即使在下面的代码示例中,将我从子表单不会
工作。



但它确实如此,否则我就不会发布它。


也许,当时你打电话给函数传递给我作为一个表格

参考,子表格实际上没有打开?

-

Darryl Kerkeslager


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]![ctrlMySubFormObject].Form
Forms![frmMyParentForm]![ctrlMySubFormObject].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

解决方案

Pass the Me reference to the function/sub.

Public Sub MoveToNext(currentRecordId 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.Clone
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(lst.ListCount - 1)
Else
If IsNull(lst.Value) 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.Value) 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.comwrote

>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.



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(currentRecordId 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.Clone
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(lst.ListCount - 1)
Else
If IsNull(lst.Value) 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.Value) 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.comwrote

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.


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("TheSubform").txtString

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


这篇关于子窗体导航的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆