D
Donna
Help! I have been trying to get the following to work for hours and keep getting the error message that the OpenForm action was cancelled....
I am trying to get a new form to open based on the selection from a list box. This is the second such screen within the database.
I can get the first one to work, but I'm stuck....
Any help would be greatly appreciated (P.S. I am a complete novice at Access - this is my first database design.) Thanks!
Private Sub cmdView_Click()
Dim strWhere As String, varItem As Variant
' If no items selected, then nothing to do
If Me!lstProjName.ItemsSelected.Count = 0 Then Exit Sub
' Loop through the items selected collection
For Each varItem In Me!lstProjName.ItemsSelected
' Grab the Project ID for each selected item
strWhere = strWhere & Chr$(34) & Me!lstProjName.Column(0, varItem) & Chr$(34) & ","
Next varItem
' Throw away the extra comma on the "IN" string
strWhere = Left$(strWhere, Len(strWhere) - 1)
' Open the projects form filtered on the selected projects
gstrWhereProject = "[ProjectID] IN (" & strWhere & ")"
DoCmd.OpenForm FormName:="frmProjects", WhereCondition:=gstrWhereProject
' Hide the subform, but show the slection list and hide buttons
Forms!frmProjects!Phasesubform.Visible = False
Forms!frmProjects!cmdReturn.Visible = False
DoCmd.RunCommand acCmdSaveRecord
End Sub
I am trying to get a new form to open based on the selection from a list box. This is the second such screen within the database.
I can get the first one to work, but I'm stuck....
Any help would be greatly appreciated (P.S. I am a complete novice at Access - this is my first database design.) Thanks!
Private Sub cmdView_Click()
Dim strWhere As String, varItem As Variant
' If no items selected, then nothing to do
If Me!lstProjName.ItemsSelected.Count = 0 Then Exit Sub
' Loop through the items selected collection
For Each varItem In Me!lstProjName.ItemsSelected
' Grab the Project ID for each selected item
strWhere = strWhere & Chr$(34) & Me!lstProjName.Column(0, varItem) & Chr$(34) & ","
Next varItem
' Throw away the extra comma on the "IN" string
strWhere = Left$(strWhere, Len(strWhere) - 1)
' Open the projects form filtered on the selected projects
gstrWhereProject = "[ProjectID] IN (" & strWhere & ")"
DoCmd.OpenForm FormName:="frmProjects", WhereCondition:=gstrWhereProject
' Hide the subform, but show the slection list and hide buttons
Forms!frmProjects!Phasesubform.Visible = False
Forms!frmProjects!cmdReturn.Visible = False
DoCmd.RunCommand acCmdSaveRecord
End Sub