UtterAccess.com
X   Site Message
(Message will auto close in 2 seconds)

Welcome to UtterAccess! Please ( Login   or   Register )

Custom Search
 
   Reply to this topicStart new topic
> Macro Expression Returns Error, Access 2016    
 
   
frankthegeezer
post Mar 7 2018, 11:11 PM
Post#1



Posts: 13
Joined: 7-March 18



Hi all,
I've been trying to do what I consider a simple expression in a macro, but for some reason it returns an error when run.

The object of the macro, to check the yes/no status of a field in a table, table name is 'Orders Update', field name is 'Stock Updated'

The field in table view appears a tickbox.

I want the macro to look at the field and if it is already ticked, to give an error message.

My expression is without quotes obviously 'if [Orders Update]![Stock Updated]=yes Then
Messagebox
Message: You have already updated stock for this order
Beep: Yes
Type: Warning!
Title: Stock Updated Warning

Else if [Orders Updated]![Stock Updated]=no Then
RunMacro
Macro Name: StockUpdate

The error is from this statement '[Orders Update]![Stock Updated]=yes'

Things I've already tried, changing yes to true, changing yes to 1, changing yes to -1, , changing the case of yes etc etc, nothing seems to work, is it just that this expression isn't possible or am I missing something?
This post has been edited by frankthegeezer: Mar 7 2018, 11:28 PM
Go to the top of the page
 
GroverParkGeorge
post Mar 7 2018, 11:54 PM
Post#2


UA Admin
Posts: 32,778
Joined: 20-June 02
From: Newcastle, WA


Welcome to UtterAccess.

What is the error raised? Please give the err number and the error description.

--------------------
Go to the top of the page
 
frankthegeezer
post Mar 8 2018, 04:45 AM
Post#3



Posts: 13
Joined: 7-March 18



Hi and thank you for the welcome,

the error is an action failed error

the error is in the condition section: Error: [Order Details]![Stock Updated]=yes

the error number is 2766 then when I close that error window it is followed by 'The object doesn't contain the automation object '|,'

I have uploaded snapshots of the macro setup plus the two errors.
This post has been edited by frankthegeezer: Mar 8 2018, 04:54 AM
Attached File(s)
Attached File  Error_1.jpg ( 43.91K )Number of downloads: 0
Attached File  Error_2.jpg ( 25.33K )Number of downloads: 0
Attached File  Macro_Setup.jpg ( 35.47K )Number of downloads: 0
 
Go to the top of the page
 
GroverParkGeorge
post Mar 8 2018, 06:53 AM
Post#4


UA Admin
Posts: 32,778
Joined: 20-June 02
From: Newcastle, WA


Okay, that is helpful. Thanks.

It appears that there is either a syntax error in the way you have specified [Orders Update]![Stock Updated], or there is no such field in that table. Please validate that reference.

Also, I would not expect "yes" to work in this context; I would expect either True/False or -1/0 to be appropriate.



--------------------
Go to the top of the page
 
frankthegeezer
post Mar 8 2018, 07:25 AM
Post#5



Posts: 13
Joined: 7-March 18



Hi George, I tried redoing from scratch again, this time using the expression builder to make sure correct table and field was selected, as per screen shot, I used True instead of yes, but got the same result.
Attached File(s)
Attached File  Expression_Builder.PNG ( 19.85K )Number of downloads: 0
Attached File  Action_Failed.jpg ( 44.23K )Number of downloads: 0
 
Go to the top of the page
 
GroverParkGeorge
post Mar 8 2018, 07:36 AM
Post#6


UA Admin
Posts: 32,778
Joined: 20-June 02
From: Newcastle, WA


I'm a bit confused because I have not used macros very much over the years, preferring VBA as the majority of Access developers do I believe.

I don't recall, however, using the Expression Builder to craft Macros, so I'm going to go have a play and see what I can see.

--------------------
Go to the top of the page
 
GroverParkGeorge
post Mar 8 2018, 07:57 AM
Post#7


UA Admin
Posts: 32,778
Joined: 20-June 02
From: Newcastle, WA


Sorry, I had to refresh my memory here.

I think the problem may be that you first have to select the table to inspect -- "Orders Update" and then filter it to the one record for which you want to evaluate "Stock Updated" for.

--------------------
Go to the top of the page
 
frankthegeezer
post Mar 8 2018, 08:24 AM
Post#8



Posts: 13
Joined: 7-March 18



OK thank you, I will see what I can come up with to narrow it down to a single record
Go to the top of the page
 
frankthegeezer
post Mar 8 2018, 11:02 PM
Post#9



Posts: 13
Joined: 7-March 18



OK just to update things as there's nothing worse than someone solving the problem and not informing others. In order to get the macro working, I had to drag the field in question onto the Order Form I was running the macro from and reference it from the form's location and as George suggested, this narrowed down the field to a certain record, so the new Macro is as attached. Thank you again George for putting me on the right path, I sometimes miss what should be obvious.
This post has been edited by frankthegeezer: Mar 8 2018, 11:03 PM
Attached File(s)
Attached File  Stock_Updated_New_Macro.jpg ( 50.06K )Number of downloads: 1
 
Go to the top of the page
 
GroverParkGeorge
post Mar 8 2018, 11:05 PM
Post#10


UA Admin
Posts: 32,778
Joined: 20-June 02
From: Newcastle, WA


We're glad you solved the problem.

Sometimes I think Macros are more obscure than they strictly need to be, as here.

Continued success with the project.

--------------------
Go to the top of the page
 


Custom Search
RSSSearch   Top   Lo-Fi    18th June 2018 - 02:31 PM