IF Statement based on tables (1 Viewer)

AC5FF

Registered User.
Local time
Today, 15:40
Joined
Apr 6, 2004
Messages
552
I can't seem to get my IF statement in a macro to work. It keeps coming up with an error "Cannot Fine Name tblImportLogDate you entered in expression"

Is there any reason this would not work?

[tblImportLogDate].[TodayRun]=Date()
or
![tblImportLogDate].[TodayRun]=Date()
(this gives the error 'Cannot find 'table' for the error)

Am I restricted to use an IF statement based on a form? if so, the data isn't on any form (new database build - no forms at all created yet).
 

AC5FF

Registered User.
Local time
Today, 15:40
Joined
Apr 6, 2004
Messages
552
Just an update:
I tried do the IF statement based on data from a form. I created a new form, with just this one piece of data from the table on it. My IF statement is now:

[Forms]![ImportLogDateTodayRun].[TodayRun]=Date()

But I get a different error:

"The object you referenced in the Visual Basic Procedure as an OLE object isn't an OLE object"

Not sure if it helps; but thought I would try and include the results here.

TIA
 

pbaldy

Wino Moderator
Staff member
Local time
Today, 13:40
Joined
Aug 30, 2003
Messages
36,125
You can't edit a table like that. Your second should work, presuming the form is bound to the table and the textbox to the field.
 

Mark_

Longboard on the internet
Local time
Today, 13:40
Joined
Sep 12, 2017
Messages
2,111
[tblImportLogDate].[TodayRun]=Date()
or
![tblImportLogDate].[TodayRun]=Date()


ACCESS would need to know what value from which record source you were trying to pull this from. ACCESS allows multiple ways of accessing the same table so you need to specify WHICH one you are using, even if you've not used one before.

This is often done by referencing a bound control on a form so that you know what data is being returned.

Simply saying "From the table" means it could be one of millions of possible values so ACCESS decides to stick its tongue out an you for it.
 

AC5FF

Registered User.
Local time
Today, 15:40
Joined
Apr 6, 2004
Messages
552
Pbaldy

Please clarify for me - Can I use a table value in an IF statement inside of a Macro?

When you put "You can't edit a table like that" is throwing me for a loop. I'm not trying to edit anything in that table - I just want to check the value of a field.

I actually stopped back to this thread to update the 'form' method works. I was doing some more searching and found a reference that the form - or more specifically the control source on the form needed to be selected to run the IF statement.

So, as part of my macro I first open the form - and since there is only one control on the form it's selected. Doing this allows the IF statement to work when written like:

[Forms]![ImportLogDateTodayRun].[TodayRun]=Date()

I'm marking the thread as solved - but would still like to verify if i am just not able to use the table directly.

Thanks!
 

pbaldy

Wino Moderator
Staff member
Local time
Today, 13:40
Joined
Aug 30, 2003
Messages
36,125
When you put "You can't edit a table like that" is throwing me for a loop. I'm not trying to edit anything in that table

Rereading, I guess what you had was in an If block. That's my lack of familiarity with macros, as I read it like I'd read code. You can read value in a table with a DLookup().
 

AC5FF

Registered User.
Local time
Today, 15:40
Joined
Apr 6, 2004
Messages
552
Thanks! I'll look up some information on Dlookup() today and give it a try!
 

Users who are viewing this thread

Top Bottom