Filter records in subform with VB code.

  • Thread starter CWH via AccessMonster.com
  • Start date
C

CWH via AccessMonster.com

I was wondering if someone can look over the code below. My main form has a
control command (buttom) for a subform. I am trying to have the control
display the message below if three fields are left blank (TeamName, Incident#,

Incident_Date). If data is entered then I would like the subform (Coordinate
Index - Incident) to open and filter just those records that have the same
incident# as the main form.

The message warning appears when the fields are blank but when I advance to a
record with data in the fields the code does not open the sub-form.

Any help would be appreicated.

..............................................................................

...........

Private Sub Command99_Click()


If Me.TeamName = False Then
If Me.Incident_ = False Then
If Me.Incident_Date = False Then

MsgBox "Enter Required Fields (Team Name, Incident#, Date) and try again.
", 48, "Data Warning..."
Exit Sub

Else

Dim stDocName As String
Dim stLinkCriteria As String
stDocName = "Forms!Coordinate Index - Incident"

stLinkCriteria = "[Incident #]=" & "'" & Me![Incident#] & "'"
DoCmd.OpenForm stDocName, , , stLinkCriteria


End If
End If
End If
End Sub
 
P

Paolo

Hi CWH,

if isnull(Me![TeamName]) or Me[TeamName]="" or isnull(Me![Incident#]) or
Me[Incident#]="" or isnull(Me![Incident_Date]) or Me[Incident_Date]="" then
MsgBox "Enter Required Fields (Team Name, Incident#, Date) and try again.
", 48, "Data Warning..."
Else
Dim stDocName As String
Dim stLinkCriteria As String
stDocName = "[Coordinate Index - Incident]"
stLinkCriteria = "[Incident #]='" & Me![Incident#] & "'"
DoCmd.OpenForm stDocName, , , stLinkCriteria

End If

HTH Paolo
 
C

CWH via AccessMonster.com

Hi Paolo;

Thank you for reviewing the code. It seems however when I enter it as listed
below the second brackets Me[TeamName], Me[Incident#], and Me[Incident_Date]
I'm getting a complie error: Expecting Then or GoTo.


Hi CWH,

if isnull(Me![TeamName]) or Me[TeamName]="" or isnull(Me![Incident#]) or
Me[Incident#]="" or isnull(Me![Incident_Date]) or Me[Incident_Date]="" then
MsgBox "Enter Required Fields (Team Name, Incident#, Date) and try again.
", 48, "Data Warning..."
Else
Dim stDocName As String
Dim stLinkCriteria As String
stDocName = "[Coordinate Index - Incident]"
stLinkCriteria = "[Incident #]='" & Me![Incident#] & "'"
DoCmd.OpenForm stDocName, , , stLinkCriteria

End If

HTH Paolo
I was wondering if someone can look over the code below. My main form has a
control command (buttom) for a subform. I am trying to have the control
[quoted text clipped - 38 lines]
End If
End Sub
 
P

Paolo

Sorry, my mistake
I forgot an exclamation mark between the me and the square bracket...
Must be me![ etc.. in all the three case.

Cheers Paolo

CWH via AccessMonster.com said:
Hi Paolo;

Thank you for reviewing the code. It seems however when I enter it as listed
below the second brackets Me[TeamName], Me[Incident#], and Me[Incident_Date]
I'm getting a complie error: Expecting Then or GoTo.


Hi CWH,

if isnull(Me![TeamName]) or Me[TeamName]="" or isnull(Me![Incident#]) or
Me[Incident#]="" or isnull(Me![Incident_Date]) or Me[Incident_Date]="" then
MsgBox "Enter Required Fields (Team Name, Incident#, Date) and try again.
", 48, "Data Warning..."
Else
Dim stDocName As String
Dim stLinkCriteria As String
stDocName = "[Coordinate Index - Incident]"
stLinkCriteria = "[Incident #]='" & Me![Incident#] & "'"
DoCmd.OpenForm stDocName, , , stLinkCriteria

End If

HTH Paolo
I was wondering if someone can look over the code below. My main form has a
control command (buttom) for a subform. I am trying to have the control
[quoted text clipped - 38 lines]
End If
End Sub
 
C

CWH via AccessMonster.com

Thanks Paolo;

I removed the brackets around stDocName and it works great...
Sorry, my mistake
I forgot an exclamation mark between the me and the square bracket...
Must be me![ etc.. in all the three case.

Cheers Paolo
Hi Paolo;
[quoted text clipped - 24 lines]
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top