vba 如何在 Access 中的特定记录处打开表单

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/24577773/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-12 03:42:18  来源:igfitidea点击:

How to open a form at a specific record in Access

vbams-accessms-access-2010openform

提问by hello123

I have a form with records for individual people with a button to view/edit a persons clearances. When I finish editing the clearance and press the Back button I want the original form (Basic Personal Information) to open at the record I have just been working on, rather than going back to record 1.

我有一个包含个人记录的表格,带有一个按钮来查看/编辑个人许可。当我完成编辑许可并按“返回”按钮时,我希望在我刚刚处理的记录中打开原始表格(基本个人信息),而不是返回到记录 1。

The code I have at present is

我目前的代码是

DoCmd.Close
DoCmd.OpenForm ("Basic Personal Information")

I have tried changing the OpenForm to

我曾尝试将 OpenForm 更改为

DoCmd.OpenForm ("Basic Personal Information"), , , "S_ID=LinkRef"

Where S_ID is the name of the field which has the persons unique ID and LinkRef is an integer of that ID. I tried a few small variations of this and eventually got it to sort of work, but it opened Basic Personal Information with only that one record available, so I couldn't look at any other people on the form (i.e. in the bottom left record navigation it was 1 of 1, when it should be for example 5 of 32).

其中 S_ID 是具有个人唯一 ID 的字段的名称,LinkRef 是该 ID 的整数。我尝试了一些小的变化并最终让它工作,但它打开了基本个人信息,只有一个可用的记录,所以我无法查看表单上的任何其他人(即在左下角的记录中)导航它是 1 中的 1,当它应该是例如 32 中的 5 时)。

Another thing I tried was adding the line

我尝试的另一件事是添加行

DoCmd.GoToRecord(acDataForm,"Basic Personal Information",acGoTo,"[S_ID] = " & LinkRef)

But obviously, the problem here is that the Offset for AcGoTo should just be a record number, so it should in this case be 5. But I don't know how to tell the program to figure out what number the record will be from the LinkRef.

但显然,这里的问题是 AcGoTo 的 Offset 应该只是一个记录号,所以在这种情况下它应该是 5。但我不知道如何告诉程序从链接参考

I hope that makes sense, if not feel free to ask me questions and I will try to explain better, otherwise any suggestions/methods will be appreciated.

我希望这是有道理的,如果不随意问我问题,我会尽量解释得更好,否则任何建议/方法将不胜感激。

Thanks

谢谢

采纳答案by parakmiakos

I would go about your problem this way :

我会这样解决你的问题:

DoCmd.OpenForm ("Basic Personal Information")
Forms("Basic Personal Information").Form.Recordset.FindFirst "[S_ID] = " & _
            Forms("PreviousForm").[LinkRef] & ""

Meaning, I would first open the form, and then move the recordset's cursor to the desired row.

意思是,我会先打开表单,然后将记录集的光标移动到所需的行。

回答by Tedo G.

maybe this help you: try to open form in dialog:

也许这对您有帮助:尝试在对话框中打开表单:

DoCmd.OpenForm ("Basic Personal Information"), , , , , acDialog

DoCmd.OpenForm ("基本个人信息"), , , , , acDialog

回答by shieldgenerator7

See this page: http://msdn.microsoft.com/en-us/library/bb237964(v=office.12).aspx

请参阅此页面:http: //msdn.microsoft.com/en-us/library/bb237964(v=office.12).aspx

I was hoping to find some kind of indexOf() method, but I don't know what the containing class is called. So, here's a work around instead, because I'm not all that familiar with VB:

我希望找到某种 indexOf() 方法,但我不知道包含的类是什么。所以,这里有一个解决方法,因为我对 VB 不是很熟悉:

You can use GoToRecordto go to the first record by passing in 0 for the fourth parameter. Then, loop through all the records using acNext, until you find the entry with the correct S_IDvalue. Then you can stop there and your entry will be the current one in the list.

您可以GoToRecord通过为第四个参数传入 0 来转到第一条记录。然后,使用 , 循环遍历所有记录acNext,直到找到具有正确S_ID值的条目。然后您可以停在那里,您的条目将成为列表中的当前条目。

It's far from perfect or optimal but it'll work if no other options are presented

它远非完美或最佳,但如果没有其他选项,它会起作用