Hola a todos.
Después de darle mil vueltas recurro a ustedes a ver si me pueden ayudar.
Tengo dos formularios. CrearForm y ModificarForm. Ambos llevan un datagrid: grillaregistros.
Los forms por separado funcionan a la perfección, el problema resulta cuando:
A) Si abro CrearForm, luego ModificarForm, al volver a CrearForm me encuentro que eldatagrid esta completamente vacio(nada, ni campos ni el formatoque aplique , nada).
B) lo mismo pero al reves..... Si abro ModificarForm, luego CrearForm , al volver a ModificarForm me encuentro que eldatagrid esta completamente vacio.
''''''''CODIGO FORM CREAR''''''
Private Sub ccmdReestablecer_Click()
LIMPIAR
End Sub
Private Sub cmdCerrar_Click()
Unload Me
End Sub
Private Sub cmdCrear_Click()
If txtNombre.Text = "" Then MsgBox "El campo GRUPO no puede estar vacio", vbInformation, "Aviso": txtNombre.SetFocus: Exit Sub
If txtInt1.Text = "" Then MsgBox "El campo Integrante 1 no puede estar vacio", vbInformation, "Aviso": txtInt1.SetFocus: Exit Sub
If txtInt2.Text = "" Then MsgBox "El campo Integrante 2 no puede estar vacio", vbInformation, "Aviso": txtInt2.SetFocus: Exit Sub
If txtInt3.Text = "" Then MsgBox "El campo Integrante 3 no puede estar vacio.En caso de que solo haya dos miembros en el grupo ponga un punto.", vbInformation, "Aviso": txtInt3.SetFocus: Exit Sub
With RsRegistros
.Requery
.AddNew
!grupo = txtNombre.Text
!fecha = DTPicker1.Value
!integrante1 = txtInt1.Text
!integrante2 = txtInt2.Text
!integrante3 = txtInt3.Text
.Update
.Requery
LIMPIAR
End With
FormatoGrillaRegistros
MsgBox " GRUPO CREADO", vbInformation, ""
Unload Me
End Sub
Private Sub Form_Load()
Skin1.LoadSkin App.Path & "\skin.skn" ''''' CARGAMOS EL SKIN
Skin1.ApplySkin RegistrosForm.hWnd '''''APLICAMOS EL SKIN A NUESTRO FORMULARIO
REGISTROS
DATOS
Set GrillaRegistros.DataSource = RsRegistros
FormatoGrillaRegistros
BLOQUEAR
End Sub
Sub LIMPIAR()
txtNombre.Text = ""
DTPicker1.Value = Date
txtInt1.Text = ""
txtInt2.Text = ""
txtInt3.Text = ""
txtNombre.SetFocus
End Sub
Sub FormatoGrillaRegistros()
With RsRegistros
GrillaRegistros.Columns(0).Width = 0
GrillaRegistros.Columns(1).Width = 2000
GrillaRegistros.Columns(2).Width = 1000
GrillaRegistros.Columns(3).Width = 3500
GrillaRegistros.Columns(4).Width = 3500
GrillaRegistros.Columns(5).Width = 3500
End With
End Sub
Sub BLOQUEAR()
GrillaRegistros.AllowUpdate = False
End Sub
''''''''CODIGO FORM MODIFICAR''''''
Private Sub ccmdReestablecer_Click()
LIMPIAR
End Sub
Private Sub cmdModificar_Click()
If lblIdregistros.Caption = "" Then MsgBox "Selecciona un Grupo a modificar", vbInformation, "Aviso": Exit Sub
If txtNombre.Text = "" Then MsgBox "El campo nombre no puede estar vacio", vbInformation, "Aviso": txtNombre.SetFocus: Exit Sub
If txtInt1.Text = "" Then MsgBox "El campo Integrante 1 no puede estar vacio", vbInformation, "Aviso": txtInt1.SetFocus: Exit Sub
If txtInt2.Text = "" Then MsgBox "El campo Integrante 2 no puede estar vacio", vbInformation, "Aviso": txtInt2.SetFocus: Exit Sub
If txtInt3.Text = "" Then MsgBox "El campo Integrante 3 no puede estar vacio.En caso de que solo haya dos miembros en el grupo ponga un punto.", vbInformation, "Aviso": txtInt3.SetFocus: Exit Sub
With RsRegistros
.Requery
.Find "IdRegistros='" & Val(lblIdregistros.Caption) & "'"
!grupo = txtNombre.Text
!fecha = DTPicker1.Value
!integrante1 = txtInt1.Text
!integrante2 = txtInt2.Text
!integrante3 = txtInt3.Text
.UpdateBatch
.Requery
LIMPIAR
BLOQUEAR
End With
FormatoGrillaRegistros
MsgBox " GRUPO MODIFICADO", vbInformation, ""
Unload Me
End Sub
Private Sub Form_Load()
Skin1.LoadSkin App.Path & "\skin.skn" ''''' CARGAMOS EL SKIN
Skin1.ApplySkin ModificarRegistrosForm.hWnd '''''APLICAMOS EL SKIN A NUESTRO FORMULARIO
REGISTROS
DATOS
Set GrillaRegistros.DataSource = RsRegistros
FormatoGrillaRegistros
BLOQUEAR
GrillaRegistros.AllowUpdate = False
End Sub
Sub FormatoGrillaRegistros()
With RsRegistros
GrillaRegistros.Columns(0).Width = 0
GrillaRegistros.Columns(1).Width = 2000
GrillaRegistros.Columns(2).Width = 1000
GrillaRegistros.Columns(3).Width = 3500
GrillaRegistros.Columns(4).Width = 3500
GrillaRegistros.Columns(5).Width = 3500
End With
End Sub
Private Sub GrillaRegistros_Click()
With RsRegistros
If .BOF Or .EOF Then Exit Sub
.Find "IdRegistros='" & Val(GrillaRegistros.Columns(0).Text) & "'"
lblIdregistros.Caption = !IdRegistros
txtNombre.Text = !grupo
DTPicker1.Value = !fecha
txtInt1.Text = !integrante1
txtInt2.Text = !integrante2
txtInt3.Text = !integrante3
DESBLOQUEAR
'lblCodigo.Caption = !IdRegistros
End With
End Sub
Sub LIMPIAR()
txtNombre.Text = ""
DTPicker1.Value = Date
txtInt1.Text = ""
txtInt2.Text = ""
txtInt3.Text = ""
txtNombre.SetFocus
End Sub
Sub BLOQUEAR()
txtNombre.Locked = True
txtInt1.Locked = True
txtInt2.Locked = True
txtInt3.Locked = True
DTPicker1.Enabled = False
End Sub
Sub DESBLOQUEAR()
txtNombre.Locked = False
txtInt1.Locked = False
txtInt2.Locked = False
txtInt3.Locked = False
DTPicker1.Enabled = True
End Sub
El caso es que en el form modificar al hacer clic me selecciona el registro a modificar, pero si se me vacia me da el error de que "conjunto de filas no esta disponible".
Mencionar que accedo a estos formularios desde los menús de un formulario MDI, y que si cierro los forms y vuelvo abrir funciona perfectamente, no se si se trata de alguna propiedad del grid pero no se exactamente donde puede estar el problema. Muchas gracias de antemano. Un saludo.