insert into sql not working...

doran_doran

Registered User.
Local time
Yesterday, 23:37
Joined
Aug 15, 2002
Messages
349
Private Sub chkDM_Click()

Dim varDM As Variant
varDM = Me.txtDLDMemail

If Me.chkDM.Value = -1 Then

'original code not working
'DoCmd.RunSQL "INSERT INTO tbltmpRecipients ( TotalRecipients ) SELECT " & varDM & " AS txtRecipient;"

'New code not working either
DoCmd.RunSQL "INSERT INTO tbltmpRecipients (TotalRecipients) values (" & varDM & ");"

ElseIf Me.chkDM.Value = 0 Then
DoCmd.RunSQL "DELETE tbltmpRecipients.TotalRecipients FROM dummy WHERE (((tbltmpRecipients.totalRecipients)=" & varDM & "));"
End If

Me.tblTmpRecipientsSubform.Requery

End Sub
 
I would use:

CurrentDb.Execute "INSERT INTO tbltmpRecipients " & _
"(TotalRecipients) SELECT " & varDM & " FROM xxxx", dbFailOnError

you should specify table (xxxx) where from you want your values to be selected.

Rgds,
giedrius
 
It's now working like a charm....

'New Working Version of the Code
Dim varDM As Variant
varDM = Me.txtDLDMemail

If Me.chkDM.Value = -1 Then
DoCmd.RunSQL "INSERT INTO tblTmpRecipients ( TotalRecipients ) SELECT " & " """ & varDM & " "" AS txtRecipient ;"
ElseIf Me.chkDM.Value = 0 Then
DoCmd.RunSQL "DELETE tbltmpRecipients.TotalRecipients FROM tbltmpRecipients WHERE (((tbltmpRecipients.totalRecipients)=" & " """ & varDM & """));"
End If

Me.tblTmpRecipientsSubform.Requery
 
Last edited:

Users who are viewing this thread

Back
Top Bottom