link criteria VB

N

neenmarie

I have a field in a form that when the data is changed I'd like another form
to open. I have set the 'dirty' event and had no problem when linking the
form with only one field. But, don't know how to write the code with two
fields linked. The code I tried to use follows. Can someone help me correct
it.
Thx much
=============================
Private Sub ECLevel_Dirty(Cancel As Integer)
Dim stDocName As String
Dim stLinkCriteria As String

stDocName = "frmECLevelChanges"

stLinkCriteria = "[PN]=" & "'" & Me![PN] & "'" And "[CustPO]=" & "'" &
Me![CustPO] & "'"
DoCmd.OpenForm stDocName, , , stLinkCriteria


End Sub
 
J

John W. Vinson

I have a field in a form that when the data is changed I'd like another form
to open. I have set the 'dirty' event and had no problem when linking the
form with only one field. But, don't know how to write the code with two
fields linked. The code I tried to use follows. Can someone help me correct
it.

I'd really use the AfterUpdate event of the control instead; it fires when the
value in the control has been changed. Something like

Private Sub ECLevel_AfterUpdate()
Dim stDocName As String
Dim stLinkCriteria As String

stDocName = "frmECLevelChanges"

stLinkCriteria = "[PN]='" & Me![PN] & "' And [CustPO]='" &
Me![CustPO] & "'"
DoCmd.OpenForm stDocName, , , stLinkCriteria


End Sub

This pieces together five string constants or variables:

[PN]='
<whatever is in Me![PN]>
' And [CustPO] = '
<whatever is in Me![CustPO]>
'

The end result is something like

[PN]='A123145' And [CustPO]='PO3315'


John W. Vinson [MVP]
 
N

neenmarie

Thank you - I'll try writing it per your example. Thank you for your help


John W. Vinson said:
I have a field in a form that when the data is changed I'd like another form
to open. I have set the 'dirty' event and had no problem when linking the
form with only one field. But, don't know how to write the code with two
fields linked. The code I tried to use follows. Can someone help me correct
it.

I'd really use the AfterUpdate event of the control instead; it fires when the
value in the control has been changed. Something like

Private Sub ECLevel_AfterUpdate()
Dim stDocName As String
Dim stLinkCriteria As String

stDocName = "frmECLevelChanges"

stLinkCriteria = "[PN]='" & Me![PN] & "' And [CustPO]='" &
Me![CustPO] & "'"
DoCmd.OpenForm stDocName, , , stLinkCriteria


End Sub

This pieces together five string constants or variables:

[PN]='
<whatever is in Me![PN]>
' And [CustPO] = '
<whatever is in Me![CustPO]>
'

The end result is something like

[PN]='A123145' And [CustPO]='PO3315'


John W. Vinson [MVP]
 

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