SubForm问题(Access 2000格式) [英] SubForm Problems (Access 2000 format)

查看:101
本文介绍了SubForm问题(Access 2000格式)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个难以解释的问题,所以请耐心等待。


数据库采用2000格式,尽管我正在进行大部分设计工作。 2007(当然保存为2000格式)


我有一个连续的frmEditConstructionLog形式,带有一个未绑定的组合框,可以将结果过滤到所需的项目编号。这很好用。


我需要添加选择多个船员的选项,这就是我被困的地方......


我无法使用子表单,因为表单处于连续表单视图中(这是必需的)。但所有尝试启动一个表单(弹出窗口)会自动将SurveyCrewLogID字段的内容插入子表单fkSurveyCrewLogID(*和*过滤子表单以仅显示那些ID)失败。


我尝试了几种方法。只有两个人有任何承诺,但两个都有问题我无法解决...


首先是一个命令按钮,它将打开一个简单的数据表视图子表(subfrmAddCrewTeamMember)与SurveyCrewLogID field和AdditionalCrew字段。问题是它会将SurveyCrewLogID插入主窗体的第一条记录中,但如果有人必须输入多个人,则SurveyCrewLogID字段仍为空。我需要自动填充该字段,并且不知道该怎么做。


第二种方法(我唯一成功的另一种方法)是使用subfrmAddCrewTeamMember的弹出窗体作为子表格。我遇到的问题是它只能在添加模式下工作(它不允许用户查看是否输入了任何其他名称),如果有人点击它并在没有输入名称的情况下退出,则输入空白值或给出了一条错误信息(取决于我是否已经填写了该字段)。当我将其编码为在编辑模式下打开时,它没有将子表单过滤到所需的SurveyCrewLogID字段。


我将发布以下两种方法的代码。希望有人能够告诉我我做错了什么,或者我能做些什么来纠正这个问题。


(我实际上更喜欢第二种方法,因为它给了用户一个概述他们正在更新的记录)


第一种方法:

I have a problem that''s difficult to explain, so please be patient.

The database is in 2000 format, though I''m doing most of the designing in 2007 (saved as 2000 format, of course)

I have a continuous form frmEditConstructionLog with an unbound combobox that filters the results to the desired project number. This works fine.

I need to add the option of choosing multiple Crew Members, and this is where I''m stuck...

I cant use a subform because the form is in Continuous Form view (which is necessary). But all attempts to launch a form (popup) that will automatically insert the contents of the SurveyCrewLogID field into the subform fkSurveyCrewLogID (*and* filter the subform to display only those IDs) have failed.

I have tried several methods. Only two have had any promise, but both had problems I was unable to solve...

First was a command button that would open a simple datasheet view subform (subfrmAddCrewTeamMember) with the SurveyCrewLogID field and AdditionalCrew fields. Problem was it will insert the SurveyCrewLogID into the first record from the main form, but if someone has to enter more than one person, the SurveyCrewLogID field remains empty. I need that field automatically populated and dont know how to do that.

The second method (the only other one that I had any success at) was a pop up form that used the subfrmAddCrewTeamMember as a subform. The problem I had with that is it only worked in Add mode (which didnt allow the user to see if there were any other names entered) and if someone clicked on it and got out without entering a name, it either entered a blank value or gave an error message (depending on whether I had made the field required). When I coded it to open in Edit mode, it didnt filter the subforms to the desired SurveyCrewLogID field.

I will post the code for both methods below. Hopefully, someone will be able to show me what I did wrong, or what I can do to correct the problem.

(I actually prefer the second method since it gives the user an overview of the record they''re updating)

First Method:

< span class =codeLinkonclick =Blur(this,this.parentNode.parentNode,getChildren(this),true);>展开 | 选择 | Wrap | 行号

推荐答案

我会在这里给你另一个选择。这是一个直接来自我的应用程序的示例,为简洁起见,删除了错误处理。它使用OpenForm的OpenArgs参数。


- 查看项目 - 表格

私有子EditProjectButton_Click()

如果ProjectNumberCombo.ListIndex< 0然后

ProjectNumberCombo = ProjectNumberCombo.Column(0,_

CurrentPage.Caption - 1)

结束如果

DoCmd.OpenForm编辑项目,,,,,,, ProjectNumberCombo

结束子


- 编辑项目 - 表格

Private Sub Form_Open(取消为整数)

Dim strProjectNumber As String

If IsNull(Me.OpenArgs)Then

MsgBox"没有指定项目。

DoCmd.Close acForm,编辑项目

退出Sub

否则

strProjectNumber = Me.OpenArgs

结束如果


''表格中只有1条记录可用于表格

Me.Filter =" ARDECProjectNumber =""" &安培; strProjectNumber& """"

Me.FilterOn = True


''初始化字段

...


另外,你可以把OpenArgs串起来,比如

DoCmd.OpenForm" Edit Project",,,,,, string1& " , &安培; string2& "," string3


然后在Form_Open中


dim strArgs()as String

strArgs = Split(Me.OpenArgs, ",")

Box1 = strArgs(0)

Box2 = strArgs(1)

Box3 = strArgs(2)


希望有所帮助。
I''ll give you another option here. This is an example straight from my application with errorhandling removed for brevity. It uses the OpenArgs argument of the OpenForm.

--View Projects-- form
Private Sub EditProjectButton_Click()
If ProjectNumberCombo.ListIndex < 0 Then
ProjectNumberCombo = ProjectNumberCombo.Column(0, _
CurrentPage.Caption - 1)
End If
DoCmd.OpenForm "Edit Project", , , , , , ProjectNumberCombo
End Sub

--Edit Project-- form
Private Sub Form_Open(Cancel As Integer)
Dim strProjectNumber As String
If IsNull(Me.OpenArgs) Then
MsgBox "No project specified."
DoCmd.Close acForm, "Edit Project"
Exit Sub
Else
strProjectNumber = Me.OpenArgs
End If

''only 1 record should be available to the form
Me.Filter = "ARDECProjectNumber = """ & strProjectNumber & """"
Me.FilterOn = True

''initialize fields
...

Also, you can string together OpenArgs like
DoCmd.OpenForm "Edit Project", , , , , , string1 & " , " & string2 & "," string3

then in Form_Open

dim strArgs() as String
strArgs = Split(Me.OpenArgs, ",")
Box1 = strArgs(0)
Box2 = strArgs(1)
Box3 = strArgs(2)

Hope that helps.


Hi Chip


听起来这样可行。唯一的问题是我真的对VBA不好,虽然看起来很简单,但我不知道在哪里放代码。


你能来吗帮助?


谢谢!
Hi Chip

Sounds like that could work. Only problem is I''m really not good with VBA and though it seems simple enough, I have no idea where to put the code.

Can you help?

Thanks!


您在弹出的新表单中拥有和想要拥有什么?
What exactly do you have and want to have in the new form you pop up?


这篇关于SubForm问题(Access 2000格式)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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