Required.Value (1 Viewer)

InFlight

User
Local time
Today, 11:06
Joined
Jun 11, 2015
Messages
130
I am using VBA to change [myTableName]![myFieldName]!Required.Value = -1
I am getting error
Error 2465 Can't find field '|1' referred to in your expression
 

pbaldy

Wino Moderator
Staff member
Local time
Yesterday, 16:06
Joined
Aug 30, 2003
Messages
36,123
What is your actual code? You can't just refer to a table like that.
 

InFlight

User
Local time
Today, 11:06
Joined
Jun 11, 2015
Messages
130
Hi
I think i may have got it by trial and error
Is this correct
Code:
    DoCmd.SetWarnings False
    db.TableDefs("Patronage").Fields("PatronageId").Required = True
    DoCmd.SetWarnings True
 

pbaldy

Wino Moderator
Staff member
Local time
Yesterday, 16:06
Joined
Aug 30, 2003
Messages
36,123
If it works, it's correct. ;)

You haven't declared or set the db variable. You can probably use CurrentDb instead, and you don't need the SetWarnings lines (I don't think anyway).
 

pbaldy

Wino Moderator
Staff member
Local time
Yesterday, 16:06
Joined
Aug 30, 2003
Messages
36,123
So did it work?

Say hi to my daughter!
 

InFlight

User
Local time
Today, 11:06
Joined
Jun 11, 2015
Messages
130
Yes it did.Thanks
I am still learning.

Cheers
 

pbaldy

Wino Moderator
Staff member
Local time
Yesterday, 16:06
Joined
Aug 30, 2003
Messages
36,123
No problem.
 

Pat Hartman

Super Moderator
Staff member
Local time
Yesterday, 19:06
Joined
Feb 19, 2002
Messages
43,204
DoCmd.SetWarnings False
db.TableDefs("Patronage").Fields("PatronageId").Required = True
DoCmd.SetWarnings True
I'm not sure what this might be doing but it isn't an update query. Are you trying to set the required property of a field to true?
 

pbaldy

Wino Moderator
Staff member
Local time
Yesterday, 16:06
Joined
Aug 30, 2003
Messages
36,123
It does set the required property to true, yes.
 

Pat Hartman

Super Moderator
Staff member
Local time
Yesterday, 19:06
Joined
Feb 19, 2002
Messages
43,204
It was the .Value reference that confused me.
 

pbaldy

Wino Moderator
Staff member
Local time
Yesterday, 16:06
Joined
Aug 30, 2003
Messages
36,123
Post 3 didn't clarify it? ;)
 

Mark_

Longboard on the internet
Local time
Yesterday, 16:06
Joined
Sep 12, 2017
Messages
2,111
Odd question, why are you setting it as required at the table level by code instead of simply updating the table definition?
 

Users who are viewing this thread

Top Bottom