I could really do with some help if someone has got the time.
I'm working on a function that, in theory, will clone all the data from my main form and those related registers from a subfrom (in the main from).
While the cloning of the data in the main form is working correctly, I'm having dificulties cloning the data from the subform.
Obviosuly, the data in the subform is tied to a query, here below is the setup of the table in the subform [Servicios_Pasajeros] :
Table Name: Pasajeros_Servicios
Field name / Property
ID / AutoNumber
ID_Servicio / Text (holds the same value as ID)
Posicion / Text
Nombre / Text
Apellido_1 / Text
Apellido_2 / Text
Nacionalidad / Text
Here's the code that I'm working on:
Important to mention that this code is not mine, it was posted by Allen Browne in 2005 (allenbrowne.com)
Dim lngID As Long
Dim strSQL As String
lngID = Me.ID_Servicio
If Me.[Servicios_Pasajeros].Form.RecordsetClone.RecordCount > 0 Then
strSQL = "INSERT INTO [Pasajeros_Servicios] ( ID_Servicio, Posicion, Nombre, Apellido_1, Apellido_2, Nacionalidad ) " & _
"SELECT " & lngID & " As NewID, Posicion, Nombre, Apellido_1, Apellido_2, Nacionalidad " & _
"FROM [Pasajeros_Servicios] WHERE ID_Servicio = " & Me.ID_Servicio & ";"
DBEngine(0)(0).Execute strSQL, dbFailOnError
Else
' Msgbox "No data to clone"
End If
After execution, I get the following error: Data type mismatch in criteria expession.
While I understand what the code is doing, I'm unable to see the cause of the error.
Anyones help would be great..
JMC014
I'm working on a function that, in theory, will clone all the data from my main form and those related registers from a subfrom (in the main from).
While the cloning of the data in the main form is working correctly, I'm having dificulties cloning the data from the subform.
Obviosuly, the data in the subform is tied to a query, here below is the setup of the table in the subform [Servicios_Pasajeros] :
Table Name: Pasajeros_Servicios
Field name / Property
ID / AutoNumber
ID_Servicio / Text (holds the same value as ID)
Posicion / Text
Nombre / Text
Apellido_1 / Text
Apellido_2 / Text
Nacionalidad / Text
Here's the code that I'm working on:
Important to mention that this code is not mine, it was posted by Allen Browne in 2005 (allenbrowne.com)
Dim lngID As Long
Dim strSQL As String
lngID = Me.ID_Servicio
If Me.[Servicios_Pasajeros].Form.RecordsetClone.RecordCount > 0 Then
strSQL = "INSERT INTO [Pasajeros_Servicios] ( ID_Servicio, Posicion, Nombre, Apellido_1, Apellido_2, Nacionalidad ) " & _
"SELECT " & lngID & " As NewID, Posicion, Nombre, Apellido_1, Apellido_2, Nacionalidad " & _
"FROM [Pasajeros_Servicios] WHERE ID_Servicio = " & Me.ID_Servicio & ";"
DBEngine(0)(0).Execute strSQL, dbFailOnError
Else
' Msgbox "No data to clone"
End If
After execution, I get the following error: Data type mismatch in criteria expession.
While I understand what the code is doing, I'm unable to see the cause of the error.
Anyones help would be great..
JMC014