Visual Basic - ING. DUPLICADO(MSFLEXGRID)

Life is soft - evento anual de software empresarial
 
Vista:

ING. DUPLICADO(MSFLEXGRID)

Publicado por CATALINA CHEVERE (1 intervención) el 07/03/2006 17:27:58
Hola tengo un MSFLEXGRID al cual le ingreso registros escribiendo sobre el. lo que quiero es que cuando escribo un codigo de producto en la 1 columna del MSFLEXGRID(al escribir el codigo en la 1 columna y al hacer enter , si este codigo se encuentra en la base de dato se desplegara los otros datos en las siguientes columnas del MSFLEXGRID de lo contrario me manda un mensaje “NO EXISTE EL CODIGO”), si este codigo ya esta escrito en la fila anterior? No me acepte o me mande un mensaje que el codigo ya fue digitado
El MSFLEXGRID me representa a una factura, ya que al imprimir el MSFLEXGRID no quiero que aparesca una factura con productos repetidos

NOTA: a proposito el codigo que tengo como ejemplo les puede servir a muchos amigos que estan aprendiendo a programar, para que sepan como se puede ingresar , modificar ,eliminar en un MSFLEXGRID actuando directamente sobre el, en otras palabras escribir,corregir lo que esta escribiendo borrando carácter por caracter todo esto combinando con la tecla enter o intro

Aquí va el codigo que estoy trabajando;

Private Sub Form_Load()
Set cnn = New Connection
Set rstabla = New Recordset

With cnn
.Provider = "microsoft.jet.oledb.4.0"
.ConnectionString = "c:\lacteos.mdb"
.Open
End With
MSHFlexGrid1.Cols = 7
MSHFlexGrid1.ColWidth(0) = 350
MSHFlexGrid1.ColWidth(1) = 785
MSHFlexGrid1.ColWidth(2) = 3970
MSHFlexGrid1.ColWidth(3) = 920
MSHFlexGrid1.ColWidth(4) = 1190
MSHFlexGrid1.ColWidth(5) = 920
MSHFlexGrid1.ColWidth(6) = 1020

MSHFlexGrid1.BackColorSel = RGB(100, 184, 150)
MSHFlexGrid1.BackColorBkg = RGB(110, 110, 110)
MSHFlexGrid1.ForeColorSel = &HFF&
MSHFlexGrid1.Rows = 2 'determina el número total de columnas o filas en el flexgrid jerárquico
MSHFlexGrid1.BackColorFixed = &HC080FF
MSHFlexGrid1.ForeColorFixed = &HFFFFFF
MSHFlexGrid1.TextMatrix(0, 0) = " Nº"
MSHFlexGrid1.TextMatrix(0, 1) = "CODIGO"
MSHFlexGrid1.TextMatrix(0, 2) = " DESCRIPCION"
MSHFlexGrid1.TextMatrix(0, 3) = "VAL.UNIT"
MSHFlexGrid1.TextMatrix(0, 4) = "UNIDAD CAJA"
MSHFlexGrid1.TextMatrix(0, 5) = "CANTIDAD"
MSHFlexGrid1.TextMatrix(0, 6) = "VALOR TOTAL"
limpiar
End Sub

'Permite editar una celda
Private Sub MSHFlexGrid1_keypress(keyascii As Integer)
If keyascii >= 32 And keyascii <= 127 Then
MSHFlexGrid1.Text = MSHFlexGrid1.Text & Chr(keyascii)
End If
Select Case keyascii
Case vbKeyReturn, vbKeyTab
'mueve para la proxima celda.
With MSHFlexGrid1

If ((.Col + 5 < .Cols - 1) Or .Col = 5) And _
IsNumeric(.TextMatrix(.Row, 5)) _
And IsNumeric(.TextMatrix(.Row, 3)) Then
.Col = .Col + 1
.TextMatrix(.Row, 6) = (.TextMatrix(.Row, 5)) * (.TextMatrix(.Row, 3))

‘si es numerico lo que se digita en la columna 6 al hacer enter se aumenta ena fila mas al MSFLEXGRID
ElseIf IsNumeric(.TextMatrix(.Row, 5)) And IsNumeric(.TextMatrix(.Row, 6)) _
And IsNumeric(.TextMatrix(.Row, 0)) Then
.Rows = .Rows + 1
.Row = .Row + 1
.Col = 1

‘ si esta con “ ” la fila del MSFLEXGRID, al hacer enter no buscara el codigo
En la base de dato
ElseIf .TextMatrix(.Row, 1) <> "" And Trim(txt_rut) <> "" And Trim(txt_razon) <> "" _
And Trim(txt_pag) <> "" And Trim(txt_fech) <> "__/__/____" And Trim(txt_fecha) <> "__/__/____" Then
If rstabla.State = 1 Then rstabla.Close
rstabla.Open " select productos.descripcion, productos.precio_unitario, " _
& " productos.unidad_caja from productos where productos.codigo = ' " & (.TextMatrix(.Row, 1)) & " ' " _
, cnn, adOpenKeyset, adLockOptimistic, adCmdText
If Not (rstabla.BOF Or rstabla.EOF) Then
rstabla.MoveFirst
Do While Not rstabla.EOF
.TextMatrix(.Row, 2) = rstabla!descripcion
.TextMatrix(.Row, 3) = Str(rstabla!precio_unitario)
.TextMatrix(.Row, 4) = rstabla!unidad_caja
rstabla.MoveNext
With MSHFlexGrid1
For x = 1 To .Rows - 1
.Col = 0
.Row = x
.Text = x
Next
End With
Loop
.Col = 5
Else
MsgBox "CODIGO NO EXISTE"
.Col = 1
End If
rstabla.Close
End If
End With
End Select
End Sub

'Permite borrar
Private Sub MSHFlexGrid1_KeyUp(KeyCode As Integer, Shift As Integer)
'manipular las teclas Supr (Del) y Retroceso (BackSpace)
Select Case KeyCode
Case vbKeyDelete
MSHFlexGrid1.Text = ""
Case vbKeyBack
If Len(MSHFlexGrid1.Text) > 0 Then
MSHFlexGrid1.Text = Left(MSHFlexGrid1.Text, Len(MSHFlexGrid1.Text) - 1)
End If
End Select
End Sub

GRACIAS....
CATALINA CHEVERE
Valora esta pregunta
Me gusta: Está pregunta es útil y esta claraNo me gusta: Está pregunta no esta clara o no es útil
0
Responder

RE:ING. DUPLICADO(MSFLEXGRID)

Publicado por Jose Alfredo (1 intervención) el 11/05/2006 01:06:49
Private Sub cboiPermisos_CloseUp()
Dim intPosDato As Integer
Dim vDatoBuscar As Variant
Dim intY As Integer

If cboiPermisos.Text <> vbNullString Then
intPosDato = mshfPermisos.Row
vDatoBuscar = cboiPermisos.Text
For intY = 1 To mshfPermisos.Rows - 1
If intY <> intPosDato Then
If vDatoBuscar = mshfPermisos.TextMatrix(intY, 1) Then
MsgBox "El permiso ya se encuentra dado de lata para este usuario", vbInformation + vbOKOnly, "Permiso Repetido"
cboiPermisos.Text = ""
Exit Sub
End If
End If
Next intY

With Me.mshfPermisos
.TextMatrix(.Row, 1) = cboiPermisos.Text
.TextMatrix(.Row, 2) = cboiPermisos.Columns(2).Text
.TextMatrix(.Row, 3) = cboiPermisos.Columns(3).Text
.TextMatrix(.Row, 4) = cboiPermisos.Columns(4).Text
.TextMatrix(.Row, 5) = Me.txtUsua_nID.Text
End With
End If
End Sub 'Sub cboiPermisos_CloseUp()

Este codgio lo utilizo para que no se inserter productos ducplidaos haber si te sive por que es lo que te estoy entendiendo si teines duda un correo del messager es unicornio_82@hotmail
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar