All,
I have the following code to insert records into temporary tables on the client.
The above is just an extract.
The breaks down when any of the [1stForename], [2ndForename] or Surname
fields contain an apostrophy, e.g. O'Neil
Also, you will see I have used Nz() for fields which could be null values,
Is there a way round this without putting in a zero.
Thanks,
I have the following code to insert records into temporary tables on the client.
Code:
DoCmd.RunSQL "DELETE * FROM tblTEMPNTCChild;"
strSQL = ""
strSQL = "SELECT tblNTCChild.NTCChildID, "
strSQL = strSQL & "[1stForename], "
strSQL = strSQL & "[2ndForename], "
strSQL = strSQL & "Surname, "
strSQL = strSQL & "Dob, "
strSQL = strSQL & "Dod, "
strSQL = strSQL & "Urn, "
strSQL = strSQL & "OutputCode "
strSQL = strSQL & "FROM tblNTCChild "
strSQL = strSQL & "INNER JOIN tblQualifingNTCChildren "
strSQL = strSQL & "ON tblNTCChild.Entid = tblQualifingNTCChildren.EntID "
strSQL = strSQL & "WHERE tblNTCChild.Entid = " & sglEntID & ";"
Set qryDef = db.CreateQueryDef("")
With qryDef
.SQL = strSQL
Set rst = .OpenRecordset()
If rst.RecordCount = 0 Then Exit Sub
Do While Not rst.EOF
'Add the record + the leading number based on i
strSQL = ""
strSQL = strSQL & "INSERT INTO tblTEMPNTCChild ( "
strSQL = strSQL & "TEMP_NTC_Number, "
strSQL = strSQL & "NtcChildId, "
strSQL = strSQL & "[1stForename], "
strSQL = strSQL & "[2ndForename], "
strSQL = strSQL & "Surname, "
strSQL = strSQL & "Dob , "
strSQL = strSQL & "Dod, "
strSQL = strSQL & "Urn, "
strSQL = strSQL & "OutputCode ) "
strSQL = strSQL & "VALUES ("
strSQL = strSQL & i & ","
strSQL = strSQL & rst!NtcChildId & ", '"
strSQL = strSQL & rst![1stForename] & "', '"
strSQL = strSQL & rst![2ndForename] & "', '"
strSQL = strSQL & rst!Surname & "', "
strSQL = strSQL & rst!Dob & ", "
strSQL = strSQL & Nz(rst!Dod, 0) & ", '"
strSQL = strSQL & rst!Urn & "', "
strSQL = strSQL & Nz(rst!OutputCode, 0) & ");"
DoCmd.RunSQL strSQL
rst.MoveNext
i = i + 1
Loop
End With
The above is just an extract.
The breaks down when any of the [1stForename], [2ndForename] or Surname
fields contain an apostrophy, e.g. O'Neil
Also, you will see I have used Nz() for fields which could be null values,
Is there a way round this without putting in a zero.
Thanks,