I've been looking for an answer to no avail, so here it goes.
I'm building an app with Access as its front end and MySQL as its back end via ODBC. I'm generating bills based on orders. Simple app, really.
Now, when I open the form (On Open event) to create the bills, I read from the order headers and assign them to the bill headers. The bills form has the header fields and the details as a subform.
When I try to write to the bill details table, I open a recordset for the order details and check if there are no previous records; if not, then I write to the table. But when I do the AddNew, comes this error:
I guessed this could be because the form hasn't written to the parent table, so I moved the procedure to the AfterUpdate event.
This is the AfterUpdate event.
I tried doing an action query via application.currentproject.connection.execute and still get this error. If I go to phpMyAdmin at this point and input the INSERT query, it works.
Dim rs As New ADODB.Recordset
Dim stSQL As String
Dim rsOrden As New ADODB.Recordset
Dim rsFactura As New ADODB.Recordset
stSQL = "SELECT idOrden,idPrograma,datFechaComercial,idTipoTarifa,bytDuracion,dblPrecioUnitario FROM tblOrdenDetalle WHERE idOrden = " & Me!idOrden & ";"
rs.Open stSQL, Application.CurrentProject.Connection, adOpenDynamic, adLockOptimistic
Rem If there are no errors on the order details, to process
If rs.EOF Then
MsgBox "There are no order details!", vbCritical, "Error"
Do While Not rs.EOF
rsFactura.Open "tblFactDetalle", Application.CurrentProject.Connection, adOpenDynamic, adLockOptimistic
rsFactura!idFact = Me!idFact
rsFactura!txtPauta = Me!txtOrdenAgencia
rsFactura!idPrograma = rs!idPrograma
rsFactura!dblCosto = rs!dblPrecioUnitario
rsFactura!bytDuracion = rs!bytDuracion
rsFactura!bytNumeroSpots = rs!bytNumeroSpots
Set rsFactura = Nothing
Set rs = Nothing
My best guess is that the parent record hasn't been saved up to this point, but haven't found a way to make sure it is so.