cparralesl
Programmer
Hi guys:
May be someone got this easy, but I spend some days around it and I already looked it up in this forum with no luck.
My purpose is to record the invoices and products the company has bought. I have created a form with subform that save that information.
If the subform has no record, hide it and make visible a check box that turn it visible. This is for validations reason.
If the status on the main form is "L" the input controls are diabled
The form allow new records and validate the required fields
If there is a new record the checkbox is visible, along the required fields entry on the main form, and hide the subform. The user has to save the current record to show the detail subform.
The problem comes when there is a new invoice record, or invoces with no detail. If for some reason the user clicks on the navigatios buttons, I lost the sub form information. The records on the sub form dessapers even though the invoice has records in the subform related.
I made som tests in a very fresh form, without all validations, and realize that after click a navigation button the subform got the focus in edit mode automatiaclly, and if I move to other record, the main form looses the link field and continue moving around not showing the detail. I did set the focus on a valid control in the current event, but have the same behavior.
Helps about it will be appreciated
Here is my code:
Cesar Humberto Parrales
Application Support
May be someone got this easy, but I spend some days around it and I already looked it up in this forum with no luck.
My purpose is to record the invoices and products the company has bought. I have created a form with subform that save that information.
If the subform has no record, hide it and make visible a check box that turn it visible. This is for validations reason.
If the status on the main form is "L" the input controls are diabled
The form allow new records and validate the required fields
If there is a new record the checkbox is visible, along the required fields entry on the main form, and hide the subform. The user has to save the current record to show the detail subform.
The problem comes when there is a new invoice record, or invoces with no detail. If for some reason the user clicks on the navigatios buttons, I lost the sub form information. The records on the sub form dessapers even though the invoice has records in the subform related.
I made som tests in a very fresh form, without all validations, and realize that after click a navigation button the subform got the focus in edit mode automatiaclly, and if I move to other record, the main form looses the link field and continue moving around not showing the detail. I did set the focus on a valid control in the current event, but have the same behavior.
Helps about it will be appreciated
Here is my code:
Code:
Option Compare Database
Private Sub ckcActivaDetalle_Click()
If Validado Then
If ComprasDetalle.Form.Visible = False Then
ComprasDetalle.Form.Visible = True
ComprasDetalle.SetFocus
Me.ckcActivaDetalle.Visible = False
Else
ComprasDetalle.Form.Visible = False
End If
Else
MsgBox "Aun no ha digitado los datos requeridos para agregar detalle de compras " _
, vbInformation + vbOKOnly, nempresa
Me.ckcActivaDetalle.Value = False
If (Len(txtNumeroFactura) = 0 Or IsNull(txtNumeroFactura)) Then txtNumeroFactura.SetFocus Else txtFechaFactura.SetFocus
End If
End Sub
Private Sub cmdGrabar_Click()
If Validado Then
DoCmd.RunCommand (acCmdSaveRecord)
Call ckcActivaDetalle_Click
Else
MsgBox "Informacion requeridos no completados", vbCritical + vbOKOnly, ""
If (Len(txtNumeroFactura) = 0 Or IsNull(txtNumeroFactura)) Then txtNumeroFactura.SetFocus Else txtFechaFactura.SetFocus
End If
End Sub
Private Sub Form_BeforeUpdate(Cancel As Integer)
If Not Validado Then
MsgBox "Datos requeridos no completados", vbCritical + vbOKOnly, nocorto
Cancel = True
Me.txtNumeroFactura.SetFocus
Else
Me.ESTADO = "A"
End If
End Sub
Private Sub Form_Current()
Me.cmdCerrar.SetFocus
'Me.txtNumeroFactura.SetFocus
With Me![ComprasDetalle].Form
If .RecordsetClone.RecordCount = 0 Then
.Visible = False
If Not Validado Then
Me.ckcActivaDetalle.Visible = False
Else
Me.ckcActivaDetalle.Visible = True
End If
Else
.Visible = True
Me.ckcActivaDetalle.Value = False
Me.ckcActivaDetalle.Visible = False
End If
End With
If Me.ESTADO = "L" Then ActivaDesactiva (False) Else ActivaDesactiva (True)
End Sub
Private Sub ActivaDesactiva(ByVal Activado As Boolean)
Dim xControl As Control
Me.cmdCerrar.SetFocus
For Each xControl In Me.Controls
If (TypeOf xControl Is TextBox) Or _
(TypeOf xControl Is SubForm) Or _
(TypeOf xControl Is CommandButton) Then
If UCase(xControl.Name) <> "CMDCERRAR" Then
Me.SetFocus
Me.Repaint
xControl.Enabled = Activado
End If
End If
Next xControl
End Sub
Private Function Validado() As Boolean
'Validacion de datos generales de compras
Dim xControl As Control
Validado = True
For Each xControl In Me.Controls
If (TypeOf xControl Is TextBox) Then
If UCase(xControl.Tag) = "REQUERIDO" And _
((Len(xControl.Value) = 0) Or IsNull(xControl.Value)) Then
Validado = False
End If
End If
Next xControl
End Function
Cesar Humberto Parrales
Application Support