Help to enable or lock fields regarding a combo box

AlvaroCity

Registered User.
Local time
Today, 17:09
Joined
Jul 16, 2016
Messages
70
Hello everyone.

"Developing" my data base I bumped into another problem. Now this time is that I am trying to set either a order is New, In process or Closed.

To do so, I created a table with these 3 States and Referential Integrity with the table Orders, so number 1 is
New, number 2 is In process and number 3 is Closed.

I had a look at Northwind 2007 to try to have an idea about how to do, but this seems to be more difficult than I first thought.

I could understand that I have to create a module with the different states ("Albaran means Order")
PHP:
Public Enum AlbaranState

    New_Albaran = 0
    InProcess_Albaran = 1
    Closed_Albaran = 2
End Enum
Then I created a subfuntion in the Albaran´s form (Order´s form)
PHP:
Sub SetformState()

    Dim State As AlbaranState
    
    If (Me.cboIDEstado.Value = 1) Then
        State = New_Albaran
    ElseIf (Me.cboIDEstado.Value = 2) Then
        State = InProcess_Albaran
    ElseIf (Me.cboIDEstado.Value = 3) Then
        State = Closed_Albaran
    End If
        
    Me.lblExportado.Visible = (State = Closed_Albaran)
    Me.imgexp.Visible = (State = Closed_Albaran)
    Me.imgedit.Visible = (State <> Closed_Albaran)
    Me.frmSubAlbaran.Locked = (State = Closed_Albaran)
    Me.txtAlbaranNumero.Enabled = (State = New_Albaran) Or (State = InProcess_Albaran)
    Me.txtFecha.Enabled = (State = New_Albaran) Or (State = InProcess_Albaran)
    Me.cboCliente.Enabled = (State = New_Albaran) Or (State = InProcess_Albaran)
       
    
End Sub
This is what I have so far. Now I dont know to assign every state to the combo that assigns if the order is new, in process or closed.


 
Last edited:
You can change the Sub to a Function, as shown below. Then you can set the After Update property of cboIDEstado to: =SetformState()
Code:
[COLOR="Navy"]Function[/COLOR] SetformState()

    [COLOR="Navy"]Dim[/COLOR] State [COLOR="Navy"]As[/COLOR] AlbaranState

    [COLOR="Navy"]If[/COLOR] (Me.cboIDEstado.Value = 1) [COLOR="Navy"]Then[/COLOR]
        State = New_Albaran
    [COLOR="Navy"]ElseIf[/COLOR] (Me.cboIDEstado.Value = 2) [COLOR="Navy"]Then[/COLOR]
        State = InProcess_Albaran
    [COLOR="Navy"]ElseIf[/COLOR] (Me.cboIDEstado.Value = 3) [COLOR="Navy"]Then[/COLOR]
        State = Closed_Albaran
    [COLOR="Navy"]End If[/COLOR]

    Me.lblExportado.Visible = (State = Closed_Albaran)
    Me.imgexp.Visible = (State = Closed_Albaran)
    Me.imgedit.Visible = (State <> Closed_Albaran)
    Me.frmSubAlbaran.Locked = (State = Closed_Albaran)
    Me.txtAlbaranNumero.Enabled = (State = New_Albaran) [COLOR="Navy"]Or[/COLOR] (State = InProcess_Albaran)
    Me.txtFecha.Enabled = (State = New_Albaran) [COLOR="Navy"]Or[/COLOR] (State = InProcess_Albaran)
    Me.cboCliente.Enabled = (State = New_Albaran) [COLOR="Navy"]Or[/COLOR] (State = InProcess_Albaran)

[COLOR="Navy"]End Function[/COLOR]
 
Hello again.

Maybe I didnt explain myself properly. I dont want to use the combobox to assign either the form is new, in process or closed.

That is something that I would like it to be done automatically.

It would be even better if instead of a combo box I used a textbox.

For example if "OrderID" is null.... It would be NEW. If either OrderID or ClientID is not null.... It would be In Process and lastly If I clicked "Export Order in pdf." It would be Closed.

I don't know how to address this problem.
 
To me you have a conflict because there are two ways that a status is determined. In one case, you are storing the status in the Order table. In the other case, you are calculating the status using these rules . . .
... if "OrderID" is null.... It would be NEW. If either OrderID or ClientID is not null.... It would be In Process and lastly If I clicked "Export Order in pdf." It would be Closed.
I would not do both. I would write a function that calculates the status based on the given rules, and in all cases where that status is required, call that function. Alternately, you can calculate the status in a query, and then use that query as your main, system-wide source for order data.
 
you should bind the combobox to a field in a table for that to work.
 
Hello everyone.

Sorry for my lack of knowledge, but I am not too sure how to do it. It seems to be really complicate.


I dont know If you could help me a little bit more about how to build that function...

Arnelgp, regarding to binding the cbo to the field to the table, its been done already.

Maybe I should just use a textbox instead. What I want is a way to see the status of the form. I thought about using a combobox just in case I needed to go back to redo the dispatch note.

Thank you for your help
 
Here's one idea for a function to calculate the status.
Code:
Function GetOrderStatus(objOrder as [I]<a class containing order data, maybe a form>[/I]) As AlbaranState
   If objOrder.IsExported Then
      GetOrderStatus = Closed_Albaran
   ElseIf Not IsNull(objOrder.ClientID) Then 
      GetOrderStatus = InProcess_Albaran
   Else
      GetOrderStatus = New_Albaran
   End If
End Function
You may need to store the fact that you have clicked the "Export Order in pdf" somewhere.

If this function is on the form that shows order data, then you can just use data on the form, like . . .
Code:
Public Property Get OrderStatus() As AlbaranState
   If Me.IsExported Then
      OrderStatus = Closed_Albaran
   ElseIf Not IsNull(Me.ClientID) Then 
      OrderStatus = InProcess_Albaran
   Else
      OrderStatus = New_Albaran
   End If
End Function
 
Hello!!
Thank you for your help.
I think I ve got it!!

Thanks for everything
 

Users who are viewing this thread

Back
Top Bottom