Visual Basic - Base de datos

Life is soft - evento anual de software empresarial
 
Vista:

Base de datos

Publicado por Aurelio Ortega (5 intervenciones) el 20/06/2001 18:37:01
Obtengo un mensajer de error No. 3426 en tiempo de ejecucion, "esta accion fue cancelada por el objeto asociado", cuando le doy click al boton de grabar registro.
El codigo es el siguiente:

Private Sub CMD_GRABAR_Click()
'MENSAJE$ = "INTRODUZCA LOS DATOS Y HAGA CLICK SOBRE LA FLECHA DERECHA"
'REPLY = MsgBox(MENSAJE$, vbOKCancel, "AÑADIR UN REGISTRO")
'If REPLY = vbOK Then
Text4.SetFocus
Data2.Recordset.AddNew
Data2.Recordset("CLAVEM") = Text4.Text
Data2.Recordset("NOMBRESM") = Text1.Text
Data2.Recordset.Update
Data2.Refresh

'End If
End Sub

Private Sub Command2_Click()
End

End Sub

Private Sub Form_Load()
'set data control properties
'ChDir App.Path
Data2.DatabaseName = "c:\comites\pan_main.mdb"
Data2.RecordSource = "Select * FROM MIEMBROS ORDER BY clavem"
Data2.Refresh
End Sub

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:Base de datos

Publicado por NADIE (45 intervenciones) el 21/06/2001 07:27:13
FIX FOR DATA CONTROL ERROR 3426 (VB4)

This code, which works fine under VB3, may generate runtime error 3426--"The action was canceled by an associated object"--in the 16-bit version of VB4:

Private Sub cmdUpdate_Click()
' Save contents of bound controls
' to underlying recordset
datCtl.Recordset.Update
End Sub

The problem seems to occur because the 16-bit version of VB4, unlike VB3, does not perform an implicit Edit method when the Data control moves to a new record. The solution is to check the record set's EditMode and perform an explicit Edit method if necessary:

Private Sub cmdUpdate_Click()
If datCtl.Recordset.EditMode = dbEditNone Then
datCtl.Recordset.Edit
End If
datCtl.Recordset.Update
End Sub

Another workaround is to replace the Update method with the Data control's UpdateRecord method, which is equivalent functionally to performing an Edit followed by an Update. The drawback is that UpdateRecord does not fire a Validate event, so don't use it if you rely on that event to perform data validation.

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