Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

VB Statement quit working

Status
Not open for further replies.

billheath

Technical User
Mar 17, 2000
299
US
I am perplexed but sure I am Doing something wrong!
The following code was working but now I get the error .. "Object doesn't support this property or method."

Private Sub Buy_BeforeUpdate(Cancel As Integer)
If Me![BUY] < Forms.Stock_Data![Lowest] Then
Forms.Stock_Data![Lowest] = Me![BUY]
End If
If Me![BUY] > Forms.Stock_Data![Highest] Then
Forms.Stock_Data![Highest] = Me![BUY]
End If


End Sub

If I make a change to the field[Buy] in the first form, I want to be able to replace a value in another table. Please help. I hope this makes sense! Bill

 
I'd replace this:
Forms.Stock_Data
with this:
Forms!Stock_Data

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Now I get an update without add or edit error. I don't understand why I need that. both tables are in the same database and both are opened. Access even evaluates the :
"If Me![BUY] < Forms.Stock_Data![Lowest] Then".

It gives me the error on the second statement.

I need to understand.
Thanks, Bill
 
How are ya billheath . . .

In general ...
[blue]The [purple]bang[/purple] operator [purple]![/purple] indicates that what follows is a user-defined item (an element of a collection). For example, use the [purple]![/purple] operator to refer to an open form, an open report, or a control on an open form or report.[/blue]
[blue]The [purple]dot[/purple] operator [purple].[/purple] usually indicates that what follows is an item defined by Microsoft Access. For example, use the [purple].[/purple] (dot) operator to refer to a property of a form, report, or control.[/blue]

See Ya! . . . . . .

Be sure to see faq219-2884 [blue]Worthy Reading![/blue] [thumbsup2]
Also faq181-2886 [blue]Worthy Reading![/blue] [thumbsup2]
 
The "me!" isn't even required, you can just use the control name itself alone, which is IMO a better way to do it because if you misspell a control name the computer gripes at compile time instead of run time when the error is discovered.

Good rule of thumb is that anything you create, like a form field or table field requires a !. Anything not created by you gets a period.

It is also good practice to assign the target form to an object.

at the top of the "me" form code module:
Dim frm As Form

in the form load event of your "me" form:

Sub _Load

'form has to be open before assigning
docmd.openforms "Stock_Data"

Set frm = Forms!Stock_Data

'now you can refer to this form anywhere in your event code by the name 'frm'

End Sub



Private Sub Command0_Click()


if BUY < frm!Lowest Then

'do something

End if



End Sub




end with


Debug.Print frm.Name


End Sub




 
^sorry about the stray "end with" in the code example above, it was pasted in by mistake, pls ignore
 
>The bang operator ! indicates that what follows is a user-defined item (an element of a collection).

For a little more info on this try thread222-717031
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top