Code for comparison of two fields between forms

D

djh0120

Hi,

I have a main form named Orders and a subform named Qty Form. I have a field
on Orders named Rev Level and one on the subform named RevLevel. The one on
Orders is an invisible field and is there for purposes of comparison. I want
to put code in the After_Update event of the RevLevel field in the Qty Form
that compares what is entered in the RevLevel field on the Qty Form against
what is entered in the Rev_Level field in the Orders form. If the two fields
don't match, I want to bring up a message box that says the fields don't
match, notify the quality manager and won't save the record at that time.
Below is what I have written but it won't work.

Private Sub RevLevel_AfterUpdate()

If Me.RevLevel = Forms.Orders.Rev_Level Then
Me.Date_Due.SetFocus
Else
MsgBox "This revision level does not match the revision level on file.
Notify the Quality Manager of this discrepancy. This record cannot be saved
at this time."
DoCmd.Close
End If
End Sub

Any help in resolving this would be appreciated.

djh0120
 
D

Duane Hookom

Which line creates the error? If it is:
Me.Date_Due.SetFocus
Then I expect Date_Due is not the name of a control on the form that is
running the code.

If the error is from another line, please tell us which one.

--
Duane Hookom
Microsoft Access MVP


djh0120 said:
Duane said:
Can you provide anything more than "but it won't work"?
[quoted text clipped - 23 lines]

Yes. I get this error message:
Runtime error 438. Object doesn't support this property or method.

I use Access a lot but I've never done much with code.
djh0120
 
D

djh0120

Duane said:
Which line creates the error? If it is:
Me.Date_Due.SetFocus
Then I expect Date_Due is not the name of a control on the form that is
running the code.

If the error is from another line, please tell us which one.
[quoted text clipped - 8 lines]
I use Access a lot but I've never done much with code.
djh0120

If Me.RevLevel = Forms.Parent.Rev_Level then


That is the line that is giving me the error message. The code is in the
after update event of the control named RevLevel.
 
R

Rick Brandt

Duane Hookom said:
Your original post had:
If Me.RevLevel = Forms.Orders.Rev_Level Then
Now it has changed to:
If Me.RevLevel = Forms.Parent.Rev_Level then

I'm not sure which is correct or causing the error. I think you could use:
If Me.RevLevel = Me.Parent.Rev_Level then

Doesn't that need to be Forms! instead of Forms. ?
 
M

Marshall Barton

djh0120 said:
If Me.RevLevel = Forms.Parent.Rev_Level then

That is the line that is giving me the error message. The code is in the
after update event of the control named RevLevel.

Since Parent is a property of a form, the use of Forms is
incorrect. Use Me.Parent.Rev_Level
 
D

djh0120 via AccessMonster.com

Marshall said:
Since Parent is a property of a form, the use of Forms is
incorrect. Use Me.Parent.Rev_Level
It works perfectly with that code. Thank you very much for your help.
djh0120
 

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