Problem about field update using function with case.

abzalali

Registered User.
Local time
Tomorrow, 04:55
Joined
Dec 12, 2012
Messages
118
Dear Experts,
I'm trying to update some field value depending two string field using a function with if and case, function below:
Code:
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:
Code:
MsgBox (checkDATI(Me.CausaleMov, Me.txt_tipomov))

It's not update those field. Please anybody help me.
 
To make the function return a value, you need to do an assignment, like . . .
Code:
Function checkDATI(s1, s2) As String
   dim r as string
   ...
[COLOR="Green"]   'code that assigns value to r[/COLOR]
   ...
   checkDATI = r  [COLOR="Green"]'assign value to function[/COLOR]
End Function
 
seems like you are using the same value for all the if statements such that if all are true, it is going to return the last item in the list of if statements that meet the criteria, is that the intent?
 
Dear sxschech,
I need to put it an array and update all field that are mentions in if statements. How could I do this?

Thanks
 
do you have some more information about what the process is supposed to do? Is it taking data from two places on a form and then populating text boxes if those text boxes are = ""?
 
Also, this code fails . . .
Code:
MsgBox (checkDATI(Me.CausaleMov, Me.txt_tipomov))
. . . because you never assign a value to your function . . .
Code:
Private Function checkDATI(tipotransazione As String, tipovendita As String) As String
Dim r As String
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"
        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"
        Case "VENDITA ARMI/MUNIZIONI"
        Case "MUNIZIONI"
    End Select

[B][COLOR="Red"]    checkDATI = ???[/COLOR][/B]
End If
 
Maybe this is what abzalali is after :confused:
Code:
If tipotransazione = "VENDITA" Then
    Select Case tipovendita
        Case "ARMI"
            If Me.txtMatricola = "" Then 
                Me.txtMatricola = "Matricola"
            End If
            If Me.txtModello = "" Then
                Me.txtMatricola = "Modello"
            Enf If
            ... etc ...
        Case "VENDITA ARMI/MUNIZIONI"
        Case "MUNIZIONI"
    End Select
End If
 

Users who are viewing this thread

Back
Top Bottom