help please! Combobox columns and rows properties

AlvaroCity

Registered User.
Local time
Today, 20:53
Joined
Jul 16, 2016
Messages
70
Hello there

Developing my database i bumped into this problem.

I wanted to compare 2 values from 2 columns of a combobox. Depending on these logical operations of these 2 values, a third text box would change its value.

This is the code that I have so far to make it clearer.

This code works but it does not compare row to row and thats what i need.

Code:
If Me.cboPedidoDetalleID.Column(6) > Me.cboPedidoDetalleID.Column(8) Then
    
    Me.txtNumeroPiezas.Value = Me.cboPedidoDetalleID.Column(8)
    
    Else
    
    Me.txtNumeroPiezas.Value = Me.cboPedidoDetalleID.Column(6)
    
    End If
Please do not hesitate to ask for more information if its needed
thank you for your help.
 
it can be triggered using AfterUpdate event of your combo.
also if you want to trigger it as the form loads, use the forms load event:

private sub combo_afterupdate()
If Me.cboPedidoDetalleID.Column(6) > Me.cboPedidoDetalleID.Column(8) Then

Me.txtNumeroPiezas.Value = Me.cboPedidoDetalleID.Column(8)

Else

Me.txtNumeroPiezas.Value = Me.cboPedidoDetalleID.Column(6)

End If
end sub


private sub form_load()
'initially set the value of combo to the first element
me.combo = me.combo.itemdata(0)
'update the third textbox
call combo_afterupdate
end sub
 
Dear Arnelgp

sorry for my lack of knowledge but in the columns there are several figures.

The problem is that when any figure from column 6 (regardless if this has been selected or not) is bigger than column 8. it automatically returns that value in particular not taking into account the rest of the figures row by row.
 
sorry i dont follow. can u give example of data in column6 and column8. then the expected result.

if you want to recurse to all list items in your combo:

Dim i As Integer
Dim v As Variant
For i = 0 To Me.cboPedidoDetalleID.ListCount-1
If Me.cboPedidoDetalleID.Column(6,i) > Me.cboPedidoDetalleID.Column(8,i) Then

v=Me.cboPedidoDetalleID.Column(8, i)

Else
v=Me.cboPedidoDetalleID.Column(6, i)
End If
Next
Me.txtNumeroPiezas.Value = v
 
Last edited:
Hello Arnelgp

I think that I know what the problem is. For some reason the comparison operation skips one of the steps and moves to Else.

I recorded a video to make it clearer

https://www.youtube.com/watch?v=lnZMgNM0xPg

If you see. the result in one of the selections I made, NumeroPiezas should be 12 but is 100 instead. That is wrong
 
Last edited:
i don't have audio card on my pc, sorry.
 
I think it is because the numbers is treated as text, so put a CInt or CLng around the 2 numbers you want to compare.

Code:
[FONT=Arial]If [B][COLOR=Red]CInt([/COLOR][/B]Me.cboPedidoDetalleID.Column(6)[B][COLOR=Red])[/COLOR][/B] > [B][COLOR=Red]CInt([/COLOR][/B]Me.cboPedidoDetalleID.Column(8)[B][COLOR=Red])[/COLOR][/B] Then[/FONT]
 
or use Val()
 
note that it can be awkward using "numbers" from columns in a combo box.

If CInt(Me.cboPedidoDetalleID.Column(6)) > CInt(Me.cboPedidoDetalleID.Column(8)) Then

the values ARE text. sometimes vba translates them to numbers, but sometimes you have to do it yourself. now if the value is blank, you get a problem, as I think it;s a zls rather than a null.

so somehow your code needs to treat a zls as a number (eg zero) in order for the cint not to fail. not straightforward to do in a single line of code.
 
It worked with If CInt(Me.cboPedidoDetalleID.Column(6)) > CInt(Me.cboPedidoDetalleID.Column(8)) Then

Thank you everyone. You are awesome!!!!
 

Users who are viewing this thread

Back
Top Bottom