user-defined type not defined (1 Viewer)

PWG

Registered User.
Local time
Today, 11:26
Joined
Jun 13, 2019
Messages
56
Could some one please explain to me what this means.
Dim Status As CustomerStatusEnum
I get a user-defined type not defined when I open my form
[Sub SetFormState(Optional fChangeFocus As Boolean = True)
If fChangeFocus Then Me.Machine_ID.SetFocus

Dim Status As CustomerStatusEnum

Status = Nz(Me![Status ID], New_Job)

Me.Machine_ID.Locked = (Status <> New_Job)
Me.Employee_ID.Locked = (Status <> New_CustomerOrder)]
 

MajP

You've got your good things, and you've got mine.
Local time
Today, 14:26
Joined
May 21, 2018
Messages
8,525
Where is customerstatusenum declared? Is it public?
 

PWG

Registered User.
Local time
Today, 11:26
Joined
Jun 13, 2019
Messages
56
Im sorry I do not know. I have started with the north wind data base and this is the code that was on the form.
Where can i find this information
 

MajP

You've got your good things, and you've got mine.
Local time
Today, 14:26
Joined
May 21, 2018
Messages
8,525
Should look like this
Code:
Public Enum CustomerOrderStatusEnum
    New_CustomerOrder = 0
    Invoiced_CustomerOrder = 1
    Shipped_CustomerOrder = 2
    Closed_CustomerOrder = 3
End Enum

You are missing the "order"
 

PWG

Registered User.
Local time
Today, 11:26
Joined
Jun 13, 2019
Messages
56
Thanks. What does this StatusEnum do? Is it needed.
 

theDBguy

I’m here to help
Staff member
Local time
Today, 11:26
Joined
Oct 29, 2018
Messages
21,454
Thanks. What does this StatusEnum do? Is it needed.

It’s like constants. They give you a better way to remember the numeric values used in the code. For example, rather than remember the value 167715435 (just made that up for right now), you can simply use vbWhite.
 

PWG

Registered User.
Local time
Today, 11:26
Joined
Jun 13, 2019
Messages
56
Thanks I found it in the modules. I will have a play with it and see iff I can get my for to do what I want.
 

PWG

Registered User.
Local time
Today, 11:26
Joined
Jun 13, 2019
Messages
56
Is it only used in the code because I have a table that I use for the fields in my form to tell me the status.Are the two related or separate. If I change one do I need to change the other
 

MajP

You've got your good things, and you've got mine.
Local time
Today, 14:26
Joined
May 21, 2018
Messages
8,525
An enumerator makes your code easier to understand.
Code:
Me.Employee_ID.Locked = (Status <> New_CustomerOrder)

easier to understand the logic than
Code:
Me.Employee_ID.Locked = (Status <> 0)

read
http://www.cpearson.com/excel/Enums.aspx
 

Users who are viewing this thread

Top Bottom