循环遍历子表单直到找到记录。 [英] Loop through subform until record found.

查看:98
本文介绍了循环遍历子表单直到找到记录。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Hello


我创建了一个组织,办公室和员工的关系数据库。一个组织有许多办公室,一个办公室有许多员工。这一切都很好。 



我有一个 主要形式(frmContacts派生自tblOrganisation) 和子表单(subfrmOffice派生自tblOffice)。 不要担心员工。



每个办公室记录都有一个OfficeID(主键)。 tblOrganisation主键作为tblOffice中的外键。
我已经创建了一个命令按钮(可视基本代码) MainForm(frmContacts),用户将OfficeID作为InputData1输入,表单导航到特定记录。 代码是:



  DLookup(" [[FKOrgID]"," tblOffice" ,_


" [OfficeID] ="& InputData1)



如果一个组织只有一个办公室,那么该命令非常有效。但是,如果组织有多个办事处,则表单将仅导航到组织和附属于该组织的第一个办事处。然后用户必须手动
点击"下一个办公室记录"。按钮(在subfrmOffice中)查找具有用户输入的RN的特定办公室。



其他字样,例如,一个组织有三个办公室,OfficeID 1,OfficeID 2和OfficeID 3.如果我想转到OfficeID 3,我当前单击我在主窗体上创建的命令按钮(frmContacts),输入3,表单显示组织
和OfficeID 1.   然后我手动点击子表单nextrecord按钮进入OfficeID 3.



我怎样才能获得与办公室OfficeID 3一起直接进入组织的命令?





以下代码几乎可以工作,但是循环遍历主窗体而不是子窗体,当然然后不是s" box-sizing:inherit; margin-bottom:0px; border:0px; padding-right:0px ; padding-vertical-align:top; -webkit-font-smoothing:antialiased; text-size-adjust:none; min-height:19px; word-wrap:break-word; font-family:'Segoe
UI',SegoeUI,'Helvetica Neue',Helvetica,Arial,sans-serif; font-size:15px;">


Dim InputData1 As Integer                    '用户输入OfficeID

Dim InputData2 As Integer                    



我!subfrmOffice.Form.txtboxOfficeID.SetFocus

InputData2 = Me!subfrmOffice.Form.txtboxOfficeID.Value



如果InputData1 = InputData2那么

     退出Sub

   另外:

  &NBSP; Do While(InputData1<> InputData2)

  &NBSP;我!subfrmOffice.Form.txtboxOfficeID.SetFocus

  &NBSP;致电GoToNextRecord 

  &NBSP;我!subfrmOffice.Form.txtboxOfficeID.SetFocus  

  &NBSP; InputData2 = Me!subfrmOffice.Form.txtboxOfficeID.Value  

  &NBSP;循环

结束如果



Public Sub GoToNextRecord()< br style ="">
DoCmd.GoToRecord ,, acNext



正如我所说,它几乎可以工作,但循环是问题。

解决方案


你能来吗?发布您的表单图片?我不确定我了解您发布的代码所在的位置。它是否在主窗体上并且您尝试导航子窗体?如果你想去OfficeID = 3并在提示符下输入3,为什么原始代码
会给你OfficeID = 1?


只是有点困惑...


Hello

I have created a relational database of organisations, offices and employees. One organisation has many offices, and one office has many employees. All good on that score. 

I have a  main form (frmContacts derived from tblOrganisation)  and a sub form (subfrmOffice derived from tblOffice).  Don't worry about the employees.

Each office record has an OfficeID (primary key). The tblOrganisation primary key as a foreign key in tblOffice.

I have created a command button (visual basic code) on the MainForm (frmContacts) whereby the user enters the OfficeID as InputData1, and the form navigates to the particular record.  The code is:

 DLookup("[FKOrgID]", "tblOffice", _

"[OfficeID] = " & InputData1)

The command works perfectly well if one organisation only has one office. However, if an organisation has several offices, the form will only navigate to the organisation and the first office attached to that organisation. The user then has to manually click "Next Office Record " button (in the subfrmOffice) to find the particular office with the RN the user input.

In otherwords, say an organisation has three offices, with OfficeID 1, OfficeID 2 and OfficeID 3. If I want to go to OfficeID 3, I currently click the command button I created on the main form (frmContacts), input 3, and the form displays the organisation and OfficeID 1.   I then manually click the subform nextrecord button to get to OfficeID 3.

How can I get the command to go straight to the organisation along with office OfficeID 3?


The following code nearly works, but the loop loops through the main form and not the subform, and of course then does not s"box-sizing:inherit;margin-bottom:0px;border:0px;padding-right:0px;padding-vertical-align:top;-webkit-font-smoothing:antialiased;text-size-adjust:none;min-height:19px;word-wrap:break-word;font-family:'Segoe UI', SegoeUI, 'Helvetica Neue', Helvetica, Arial, sans-serif;font-size:15px;">

Dim InputData1 As Integer                    'User inputs OfficeID
Dim InputData2 As Integer                    

Me!subfrmOffice.Form.txtboxOfficeID.SetFocus
InputData2 = Me!subfrmOffice.Form.txtboxOfficeID.Value

If InputData1 = InputData2 Then
     Exit Sub
    Else:
    Do While (InputData1 <> InputData2)
    Me!subfrmOffice.Form.txtboxOfficeID.SetFocus
    Call GoToNextRecord 
    Me!subfrmOffice.Form.txtboxOfficeID.SetFocus  
    InputData2 = Me!subfrmOffice.Form.txtboxOfficeID.Value  
    Loop
End If

Public Sub GoToNextRecord()
DoCmd.GoToRecord , , acNext

As I said, it nearly works, but the loop is the problem.

解决方案

Hi,

Can you post an image of your form? I am not sure I understand where the code you posted is located. Is it on a main form and you're trying to navigate a subform? If you wanted to go to OfficeID=3 and entered 3 at the prompt, why would the original code give you OfficeID=1?

Just a little confused...


这篇关于循环遍历子表单直到找到记录。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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