about field update using function with case

56 views Asked by At

I'm trying to update some field value depending two string field using a function with If and Case, function below:

Private Function checkDATI(tipotransazione As String, tipovendita As String) As String

Dim r As String
r = ""
If tipotransazione = "VENDITA" Then
    Select Case tipovendita
        Case "ARMI"
            If Me.txtMatricola = "" Then r = "Matricola"
            If Me.txtModello = "" Then r = "Modello"
            If Me.txtCalibro = "" Then r = "Calibro"
            If Me.txtTipoArma = "" Then r = "Tipo Arma"
            If Me.txtFabrica = "" Then r = "Fabbrica"
        Case "VENDITA ARMI/MUNIZIONI"
        Case "MUNIZIONI"
    End Select
End If

If tipotransazione = "ACQUISTO" Then
    Select Case tipovendita
        Case "ARMI"
            If Me.txtMatricola = "" Then r = "Matricola"
            If Me.txtModello = "" Then r = "Modello"
            If Me.txtCalibro = "" Then r = "Calibro"
            If Me.txtTipoArma = "" Then r = "Tipo Arma"
            If Me.txtFabrica = "" Then r = "Fabbrica"
        Case "VENDITA ARMI/MUNIZIONI"
        Case "MUNIZIONI"
    End Select
End If

checkDATI = r

End Function

And then when I call this function in a command button event as:

MsgBox (checkDATI(Me.CausaleMov, Me.txt_tipomov))

It's not updating that field. What is wrong?

1

There are 1 answers

0
Newd On

When you say:

If Me.txtMatricola = "" Then r = "Matricola"

What you are doing is assigning the value: "Matricola" to the variable:r. Instead what I think you want is this:

If Me.txtMatricola = "" Then Me.txtMatricola  = "Matricola" 

This actually sets the value of the field: txtMatricola to "Matricola". This goes for all of the fields that are in your Case statements.