help please! Combobox columns and rows properties (1 Viewer)

AlvaroCity

Registered User.
Local time
Today, 12:16
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.
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Today, 19:16
Joined
May 7, 2009
Messages
19,246
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
 

AlvaroCity

Registered User.
Local time
Today, 12:16
Joined
Jul 16, 2016
Messages
70
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.
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Today, 19:16
Joined
May 7, 2009
Messages
19,246
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:

AlvaroCity

Registered User.
Local time
Today, 12:16
Joined
Jul 16, 2016
Messages
70
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:

arnelgp

..forever waiting... waiting for jellybean!
Local time
Today, 19:16
Joined
May 7, 2009
Messages
19,246
i don't have audio card on my pc, sorry.
 

AlvaroCity

Registered User.
Local time
Today, 12:16
Joined
Jul 16, 2016
Messages
70
Hello Arnlgp. Well I dont speak on the video either :D :D
 

JHB

Have been here a while
Local time
Today, 13:16
Joined
Jun 17, 2012
Messages
7,732
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]
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Today, 19:16
Joined
May 7, 2009
Messages
19,246
or use Val()
 

gemma-the-husky

Super Moderator
Staff member
Local time
Today, 12:16
Joined
Sep 12, 2006
Messages
15,718
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.
 

AlvaroCity

Registered User.
Local time
Today, 12:16
Joined
Jul 16, 2016
Messages
70
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

Top Bottom