Problemas con Formulario
Publicado por Claudio C. (43 intervenciones) el 13/06/2007 17:42:01
Buenos dias a todos, aca en Mexico.
Tengo un problema con un userform.
En él, hay una serie de textbox, checkbox y optionbutton.
Bien describo brevemente la parte que me está dando problemas:
Tengo un textbox llamado txtClave, el código está pensado para que efectúe una búsqueda en una base de datos y según con lo que obtenga le modificará el caption a dos etiquetas q están a su lado, hasta ahí esto funciona a la perfección, pero si el usuario ingresa una clave en dicho textbox (algo que no debería suceder, pero es posible) debe marcar un error y seleccionar de nuevo el textbox en comento, pues bien, esto último NO sucede.
El código es el siguiente:
Private Sub txtClave_AfterUpdate()
Dim CveCli$
CveCli = txtClave.Value
Call buskClave(CveCli)
End Sub
Option Explicit
Private Sub buskClave(CveCli As String)
Dim InicioB$, FinalB$
Dim NomClieB$, RFCClieB$
Dim CoincideB As Range
If CveCli = 0 Then
Label16.Caption = "C A N C E L A D A"
txtSerInv.Enabled = True
txtFolInv.Enabled = True
txtFecInv.Enabled = True
txtImportInv.Enabled = False
txtIVAInv.Enabled = False
chkIVA.Enabled = False
txtRetISR.Enabled = False
chkRtISR.Enabled = False
txtRetIVA.Enabled = False
chkRtIVA.Enabled = False
txtFecPago.Enabled = False
optEfe.Enabled = False
optChq.Enabled = False
txtNumChq.Enabled = False
optTransf.Enabled = False
txtRefTran.Enabled = False
txtSerInv.SetFocus
Exit Sub
Else
Sheets("CC").Visible = True
ActiveWorkbook.Sheets("CC").Activate
ActiveWindow.DisplayGridlines = False
InicioB = "$A$7"
Range(InicioB).Select
Do
If IsEmpty(ActiveCell) = False Then
ActiveCell.Offset(1, 0).Select
End If
Loop Until IsEmpty(ActiveCell) = True
FinalB = ActiveCell.Offset(-1, 0).Address
'Establecemos nuestro rango de búsqueda e iniciamos con la operación
ActiveWorkbook.Names.Add Name:="RanBusqCve", RefersToR1C1:=Range(InicioB, FinalB)
Application.GoTo Reference:="RanBusqCve"
Set CoincideB = Selection.Find(What:=CveCli, After:=ActiveCell, LookIn:=xlValues, LookAt:=xlPart, _
SearchOrder:=xlByColumns, SearchDirection:=xlNext, MatchCase:=False, SearchFormat:=False)
If Not CoincideB Is Nothing Then
CoincideB.Activate
With ActiveCell
NomClieB = UCase(.Offset(0, 2).Value)
RFCClieB = UCase(.Offset(0, 3).Value)
End With
Label16.Caption = NomClieB
mRFC.Caption = RFCClieB
Sheets("CC").Visible = False
Exit Sub
txtSerInv.SetFocus
Else
MsgBox "La clave " & CveCli & " no existe", vbExclamation, "Clave inválida"
Sheets("CC").Visible = False
Exit Sub
frmCaptura.txtClave.SetFocus
txtClave.Text = txtClave.SelText
End If
End If
End Sub
Por otro lado, no he logrado hacer funcionar el boton "Limpiar", así que me vi obligado a hacer algo como lo siguiente:
Private Sub cmdClearForm_Click()
Unload Me
frmCaptura.Show
'Call UserForm_Initialize
End Sub
Se supone que debería funcionar sencillamente con la instrucción que aparece como comentario, pero me marca un error. Y dicho error me envia precisamente al codigo de buskClave(CveCli As String) en la línea: If CveCli = 0 Then
Agradecere toda la ayuda q puedan proporcionarme, gracias.
Tengo un problema con un userform.
En él, hay una serie de textbox, checkbox y optionbutton.
Bien describo brevemente la parte que me está dando problemas:
Tengo un textbox llamado txtClave, el código está pensado para que efectúe una búsqueda en una base de datos y según con lo que obtenga le modificará el caption a dos etiquetas q están a su lado, hasta ahí esto funciona a la perfección, pero si el usuario ingresa una clave en dicho textbox (algo que no debería suceder, pero es posible) debe marcar un error y seleccionar de nuevo el textbox en comento, pues bien, esto último NO sucede.
El código es el siguiente:
Private Sub txtClave_AfterUpdate()
Dim CveCli$
CveCli = txtClave.Value
Call buskClave(CveCli)
End Sub
Option Explicit
Private Sub buskClave(CveCli As String)
Dim InicioB$, FinalB$
Dim NomClieB$, RFCClieB$
Dim CoincideB As Range
If CveCli = 0 Then
Label16.Caption = "C A N C E L A D A"
txtSerInv.Enabled = True
txtFolInv.Enabled = True
txtFecInv.Enabled = True
txtImportInv.Enabled = False
txtIVAInv.Enabled = False
chkIVA.Enabled = False
txtRetISR.Enabled = False
chkRtISR.Enabled = False
txtRetIVA.Enabled = False
chkRtIVA.Enabled = False
txtFecPago.Enabled = False
optEfe.Enabled = False
optChq.Enabled = False
txtNumChq.Enabled = False
optTransf.Enabled = False
txtRefTran.Enabled = False
txtSerInv.SetFocus
Exit Sub
Else
Sheets("CC").Visible = True
ActiveWorkbook.Sheets("CC").Activate
ActiveWindow.DisplayGridlines = False
InicioB = "$A$7"
Range(InicioB).Select
Do
If IsEmpty(ActiveCell) = False Then
ActiveCell.Offset(1, 0).Select
End If
Loop Until IsEmpty(ActiveCell) = True
FinalB = ActiveCell.Offset(-1, 0).Address
'Establecemos nuestro rango de búsqueda e iniciamos con la operación
ActiveWorkbook.Names.Add Name:="RanBusqCve", RefersToR1C1:=Range(InicioB, FinalB)
Application.GoTo Reference:="RanBusqCve"
Set CoincideB = Selection.Find(What:=CveCli, After:=ActiveCell, LookIn:=xlValues, LookAt:=xlPart, _
SearchOrder:=xlByColumns, SearchDirection:=xlNext, MatchCase:=False, SearchFormat:=False)
If Not CoincideB Is Nothing Then
CoincideB.Activate
With ActiveCell
NomClieB = UCase(.Offset(0, 2).Value)
RFCClieB = UCase(.Offset(0, 3).Value)
End With
Label16.Caption = NomClieB
mRFC.Caption = RFCClieB
Sheets("CC").Visible = False
Exit Sub
txtSerInv.SetFocus
Else
MsgBox "La clave " & CveCli & " no existe", vbExclamation, "Clave inválida"
Sheets("CC").Visible = False
Exit Sub
frmCaptura.txtClave.SetFocus
txtClave.Text = txtClave.SelText
End If
End If
End Sub
Por otro lado, no he logrado hacer funcionar el boton "Limpiar", así que me vi obligado a hacer algo como lo siguiente:
Private Sub cmdClearForm_Click()
Unload Me
frmCaptura.Show
'Call UserForm_Initialize
End Sub
Se supone que debería funcionar sencillamente con la instrucción que aparece como comentario, pero me marca un error. Y dicho error me envia precisamente al codigo de buskClave(CveCli As String) en la línea: If CveCli = 0 Then
Agradecere toda la ayuda q puedan proporcionarme, gracias.
Valora esta pregunta


0