Pues bajate el proyect, ajustalo y nos cuentas!!
http://dl.dropbox.com/u/23151936/Foro/Ferret.rar
Codigo:
Código vb:
Ver originalPublic Conexion As ADODB.Connection
Private Sub cboFAMILIA_Click()
Dim rstData As ADODB.Recordset
Dim Secuencia As Integer
Set rstData = New ADODB.Recordset
Secuencia = 0
txtARTICULO.Text = Empty
'OBTENER EL CODIGO
rstData.Open "SELECT * FROM ARTICULOS WHERE CFAMILIA='" & cboFAMILIA.Text & "'", Conexion, adOpenDynamic, adLockBatchOptimistic
If rstData.EOF = False Then
Secuencia = Val(Mid(rstData!CCODIGO, 2))
Do While rstData.EOF = False
If Secuencia < Val(Mid(rstData!CCODIGO, 2)) Then Secuencia = Val(Mid(rstData!CCODIGO, 2))
rstData.MoveNext
Loop
txtCODIGO.Text = Mid(cboFAMILIA.Text, 1, 1) & Format(Secuencia + 1, "000")
End If
If rstData.State = 1 Then
rstData.Close
Set rstData = Nothing
End If
End Sub
Private Sub cmdGUARDAR_Click()
Dim strINSERT As String
Dim Guardado As Integer
Guardado = 0
If Trim(txtARTICULO.Text) <> Empty Then
strINSERT = "INSERT INTO ARTICULOS (CCODIGO, CFAMILIA, CARTICULO) VALUES ('" _
& txtCODIGO.Text & "','" & _
cboFAMILIA.Text & "','" & _
Trim(txtARTICULO.Text) & "')"
Conexion.Execute strINSERT, Guardado
If Guardado = 1 Then
MsgBox "ARTICULO GUARDADO!!", vbInformation
cboFAMILIA_Click
txtARTICULO.SetFocus
Else
MsgBox "NO SE PUDO GUARDAR EL ARTICULO!!", vbInformation
End If
End If
End Sub
Private Sub Form_Load()
Dim rstData As ADODB.Recordset
Set Conexion = New ADODB.Connection
Set rstData = New ADODB.Recordset
'CONEXION A LA BD
Conexion.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;" _
& "Data Source=" & App.Path & "\FERRET.mdb;Persist Security Info=False"
Conexion.Open
'CARGAR EL COMBO
rstData.Open "SELECT DISTINCT CFAMILIA FROM ARTICULOS", Conexion, adOpenDynamic, adLockBatchOptimistic
If rstData.EOF = False Then
cboFAMILIA.Clear
Do While rstData.EOF = False
cboFAMILIA.AddItem rstData!CFAMILIA
rstData.MoveNext
Loop
If cboFAMILIA.ListCount > 0 Then cboFAMILIA.Text = cboFAMILIA.List(0)
End If
If rstData.State = 1 Then
rstData.Close
Set rstData = Nothing
End If
End Sub
Private Sub Form_Unload(Cancel As Integer)
'CERRAR LA CONEXION
If Conexion.State = 1 Then
Conexion.Close
Set Conexion = Nothing
End If
End Sub