将子表单从被调用表单移动到新记录
Move subform to new record from called form
我正在努力解决所描述的问题 here。使用从主窗体调用的弹出窗口 window,我想将记录添加到 table,更新显示来自 table 的数据的连续子窗体,然后将子窗体移动到已添加记录。
但是,该解决方案不起作用,它抛出与 here 描述的相同的错误。下面是此设置的代码。
Private Sub Form_Load()
Set prevForm = Screen.ActiveForm
Me.cbo_EventCat = prevForm!cbo_EventCatSel2
Me.cbo_EventType = prevForm!cbo_EventTypeSel2
Me.cbo_SeasonStart = 1
Me.cbo_SeasonEnd = 1
Me.cbo_CostType = 1
Me.txt_MinCost = ""
Me.txt_MaxCost = ""
Me.box_NewComments.Visible = False
Me.txt_NewComments.Visible = False
Me.box_OriginalComments.Visible = False
Me.txt_OriginalComments.Visible = False
Me.cbo_ExistingComments_Sel.Visible = False
Me.box_NewBuiltComments.Visible = False
Me.txt_NewBuiltComments.Visible = False
End Sub
Private Sub btn_SubmitAndReturn_Click()
Dim strSQL, strSQLflds, strSQLvals, formName, strSubform As String
Dim db As DAO.Database
Dim rs As DAO.Recordset
Dim recID As Integer
Dim anyReqFldBlank As Boolean
Set db = CurrentDb
anyReqFldBlank = False
strSQLflds = "INSERT INTO t_EventDetails (fkEventType,fkSeasonStart"
strSQLvals = "VALUES (" & Me.cbo_EventType & ", " & Me.cbo_SeasonStart
If Me.cbo_SeasonStart = 1 Then
Me.cbo_SeasonStart.BorderColor = RGB(255, 0, 0)
anyReqFldBlank = True
Else
Me.cbo_SeasonStart.BorderColor = RGB(0, 0, 0)
anyReqFldBlank = False
End If
If Me.cbo_SeasonStart > 2 Then
If Me.cbo_SeasonEnd = 1 Then
Me.cbo_SeasonEnd.BorderColor = RGB(255, 0, 0)
anyReqFldBlank = True
Else
Me.cbo_SeasonEnd.BorderColor = RGB(0, 0, 0)
anyReqFldBlank = False
strSQLflds = strSQLflds & ",fkSeasonEnd"
strSQLvals = strSQLvals & ", " & Me.cbo_SeasonEnd
End If
End If
If Me.cbo_CostType = 1 Then
Me.cbo_CostType.BorderColor = RGB(255, 0, 0)
anyReqFldBlank = True
Else
Me.cbo_CostType.BorderColor = RGB(0, 0, 0)
anyReqFldBlank = False
strSQLflds = strSQLflds & ",fkCostType"
strSQLvals = strSQLvals & ", " & Me.cbo_CostType
If Me.cbo_CostType = 3 Then
strSQLflds = strSQLflds & ",MinCost"
strSQLvals = strSQLvals & ", " & Me.txt_MinCost
ElseIf Me.cbo_CostType = 5 Then
strSQLflds = strSQLflds & ",MinCost,MaxCost"
strSQLvals = strSQLvals & ", " & Me.txt_MinCost & ", " & Me.txt_MaxCost
Else
End If
End If
If Me.cbo_CommentsSel > 1 Then
strSQLflds = strSQLflds & ",fkComments"
strSQLvals = strSQLvals & ", " & Me.cbo_CommentsSel
End If
If anyReqFldBlank = True Then
MsgBox ("Fill in required information.")
Exit Sub
Else
strSQL = strSQL & strSQLflds & ") " & strSQLvals & ");"
MsgBox ("strSQL = " & strSQL)
db.Execute strSQL, dbFailOnError
prevForm!chd_EventDetails2.SetFocus
prevForm!chd_EventDetails2.Requery
DoCmd.GoToRecord , , acLast
DoCmd.Close acForm, "f_AddEventInfo", acSaveNo
End If
End Sub
我也尝试过这些技术,但遇到了各种问题。
Set rs = db.OpenRecordset("SELECT * FROM t_EventDetails")
rs.MoveLast
DoCmd.GoToRecord , , acGoto, rs!fkID
使 Access 抛出错误,说我无法转到该记录。
DoCmd.GoToRecord , , acLast
什么都不做,也不会抛出任何错误。
我不知道如何解决这个问题。
尝试使用子表单的 RecordsetClone:
Dim frm As Form
Dim rst As DAO.Recordset
Set frm = Forms!MainForm!SubformControlName.Form
frm.Requery
Set rst = frm.RecordsetClone
rst.MoveLast
' Sync form to recordset.
frm.Bookmark = rst.Bookmark
rst.Close
Set rst = Nothing
Set frm = Nothing
我正在努力解决所描述的问题 here。使用从主窗体调用的弹出窗口 window,我想将记录添加到 table,更新显示来自 table 的数据的连续子窗体,然后将子窗体移动到已添加记录。
但是,该解决方案不起作用,它抛出与 here 描述的相同的错误。下面是此设置的代码。
Private Sub Form_Load()
Set prevForm = Screen.ActiveForm
Me.cbo_EventCat = prevForm!cbo_EventCatSel2
Me.cbo_EventType = prevForm!cbo_EventTypeSel2
Me.cbo_SeasonStart = 1
Me.cbo_SeasonEnd = 1
Me.cbo_CostType = 1
Me.txt_MinCost = ""
Me.txt_MaxCost = ""
Me.box_NewComments.Visible = False
Me.txt_NewComments.Visible = False
Me.box_OriginalComments.Visible = False
Me.txt_OriginalComments.Visible = False
Me.cbo_ExistingComments_Sel.Visible = False
Me.box_NewBuiltComments.Visible = False
Me.txt_NewBuiltComments.Visible = False
End Sub
Private Sub btn_SubmitAndReturn_Click()
Dim strSQL, strSQLflds, strSQLvals, formName, strSubform As String
Dim db As DAO.Database
Dim rs As DAO.Recordset
Dim recID As Integer
Dim anyReqFldBlank As Boolean
Set db = CurrentDb
anyReqFldBlank = False
strSQLflds = "INSERT INTO t_EventDetails (fkEventType,fkSeasonStart"
strSQLvals = "VALUES (" & Me.cbo_EventType & ", " & Me.cbo_SeasonStart
If Me.cbo_SeasonStart = 1 Then
Me.cbo_SeasonStart.BorderColor = RGB(255, 0, 0)
anyReqFldBlank = True
Else
Me.cbo_SeasonStart.BorderColor = RGB(0, 0, 0)
anyReqFldBlank = False
End If
If Me.cbo_SeasonStart > 2 Then
If Me.cbo_SeasonEnd = 1 Then
Me.cbo_SeasonEnd.BorderColor = RGB(255, 0, 0)
anyReqFldBlank = True
Else
Me.cbo_SeasonEnd.BorderColor = RGB(0, 0, 0)
anyReqFldBlank = False
strSQLflds = strSQLflds & ",fkSeasonEnd"
strSQLvals = strSQLvals & ", " & Me.cbo_SeasonEnd
End If
End If
If Me.cbo_CostType = 1 Then
Me.cbo_CostType.BorderColor = RGB(255, 0, 0)
anyReqFldBlank = True
Else
Me.cbo_CostType.BorderColor = RGB(0, 0, 0)
anyReqFldBlank = False
strSQLflds = strSQLflds & ",fkCostType"
strSQLvals = strSQLvals & ", " & Me.cbo_CostType
If Me.cbo_CostType = 3 Then
strSQLflds = strSQLflds & ",MinCost"
strSQLvals = strSQLvals & ", " & Me.txt_MinCost
ElseIf Me.cbo_CostType = 5 Then
strSQLflds = strSQLflds & ",MinCost,MaxCost"
strSQLvals = strSQLvals & ", " & Me.txt_MinCost & ", " & Me.txt_MaxCost
Else
End If
End If
If Me.cbo_CommentsSel > 1 Then
strSQLflds = strSQLflds & ",fkComments"
strSQLvals = strSQLvals & ", " & Me.cbo_CommentsSel
End If
If anyReqFldBlank = True Then
MsgBox ("Fill in required information.")
Exit Sub
Else
strSQL = strSQL & strSQLflds & ") " & strSQLvals & ");"
MsgBox ("strSQL = " & strSQL)
db.Execute strSQL, dbFailOnError
prevForm!chd_EventDetails2.SetFocus
prevForm!chd_EventDetails2.Requery
DoCmd.GoToRecord , , acLast
DoCmd.Close acForm, "f_AddEventInfo", acSaveNo
End If
End Sub
我也尝试过这些技术,但遇到了各种问题。
Set rs = db.OpenRecordset("SELECT * FROM t_EventDetails")
rs.MoveLast
DoCmd.GoToRecord , , acGoto, rs!fkID
使 Access 抛出错误,说我无法转到该记录。
DoCmd.GoToRecord , , acLast
什么都不做,也不会抛出任何错误。
我不知道如何解决这个问题。
尝试使用子表单的 RecordsetClone:
Dim frm As Form
Dim rst As DAO.Recordset
Set frm = Forms!MainForm!SubformControlName.Form
frm.Requery
Set rst = frm.RecordsetClone
rst.MoveLast
' Sync form to recordset.
frm.Bookmark = rst.Bookmark
rst.Close
Set rst = Nothing
Set frm = Nothing