我想知道在用户选择记录的选择框控件之后立即放入代码字符串的首选函数,以便他的选择被确认并包含为“true”。简而言之,我有一个表单,用户使用一个选择框来指示要选择的记录,然后执行一个命令,其中我有代码应该复制并粘贴他选择的记录。不幸的是,在运行执行复制/粘贴命令时选择的最后一条记录无法识别。我知道我可能需要添加一个功能,例如“转到下一条记录”但是我不确定这是否是最佳方式,或者是否有一种更标准的方式,程序员使用它来不丢失所选的最后一条记录。以下是我目前使用的代码,该代码目前没有获取用户选择的最后一条记录。
Private Sub Comando99_Click()
If CurrentRecord = Recordset.RecordCount And CurrentRecord <> 1 Then
DoCmd.GoToRecord , "", acFirst
Else
DoCmd.GoToRecord , "", acNext
End If
Dim intAnswer As Integer
On Error GoTo HandleError
intAnswer = _
MsgBox("Are you sure you want to add these dependencies to your dependency project tracker?", _
vbQuestion + vbYesNo, "Add Dependencies")
If intAnswer = vbYes Then
st_sql = "INSERT INTO [tblDependencies] ( [Description] )SELECT [tblDependencyTypeListing].[Dependency (General)] FROM [tblDependencyTypeListing] WHERE ((([tblDependencyTypeListing].[ToIncludeInProject])=True))"
Application.DoCmd.RunSQL (st_sql)
st_sql = "UPDATE[tblDependencies],[tblHoldingProjectid]SET[tblDependencies].[ID Project]=[tblholdingprojectid].[ID_Project]where([tbldependencies].[ID Project])=0 and ([tblholdingprojectid].[ID_Project])is not null"
Application.DoCmd.RunSQL (st_sql)
st_sql = "UPDATE[tblDependencies]SET[tblDependencies].[Automatic date of entry]=now() where([tblDependencies].[Automatic date of entry])is null"
Application.DoCmd.RunSQL (st_sql)
st_sql = "UPDATE[tblContacts],[tblDependencies]SET[tblDependencies].[Automatic user entry]=[tblContacts].[Complete name]where([tblContacts].[In use])is not null and([tblDependencies].[Automatic user entry])is null"
Application.DoCmd.RunSQL (st_sql)
st_sql = "UPDATE[tblDependencytypelisting]SET[tblDependencytypelisting].[toincludeinproject]=null"
Application.DoCmd.RunSQL (st_sql)
Me.Refresh
End If
ExitHere:
Exit Sub
HandleError:
MsgBox "Error is " & Err.Description
Resume ExitHere
End Sub
答案 0 :(得分:0)
通过在例程开头输入以下IF语句来解决问题,以确保在运行代码之前,ACCESS移动到下一条记录以确保它确认最后一次修改
If CurrentRecord = Recordset.RecordCount And CurrentRecord <> 1 Then
DoCmd.GoToRecord , "", acFirst
Else
DoCmd.GoToRecord , "", acNext
End If