Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Problem cloning data from a subform

Status
Not open for further replies.

jmc014

Technical User
Nov 24, 2007
80
0
0
ES
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 would first put in a debug.print statement so we can see the actual sql string.
My first guess is that ID_Servicio is not a long in the table you are inserting it to or getting it from.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top