have you put in the debug.print statements I originally gave you as part of the code to see if it's actually returning a value:
Code:
Dim olNS As NameSpace
Dim item As Object
Dim Inbox As MAPIFolder
Dim SubInbox As MAPIFolder
Set olNS = GetNamespace("MAPI")
Set Inbox = olNS.GetDefaultFolder(olFolderInbox)
Set SubInbox = Inbox.Folders("TEST")
dim sSQL as string
For Each item In SubInbox.Items
If TypeOf item Is MailItem Then
With item
debug.print .subject
debug.print .to
debug.print .body
'if you get values in these debug.print statements you can move on to the SQL which in your example won't work
DoCmd.RunSQL "INSERT INTO TEST(subject, to) SELECT '" & & "','" & .To & "'"
End With
End If
Next item
Set ns = Nothing
Set olNS = Nothing
Set Inbox = Nothing
Set SubInbox = Nothing
Your SQL will not work because you're appending 1 record with predetermined values so you have to use the VALUES statement not the SELECT. you would use SELECT (I explained this in your other thread too I think) when you are trying to bulk add records from one table to another.
Code:
dim sSQL as string
ssql = "INSERT INTO TEST(subject, to) VALUES (" & Quote(.Subject) & ", " & Quote(.To) & ")"
debug.print ssql
DoCmd.RunSQL
using the debug.print statement on your SQL string will allow you to cut and paste it into a query window and see if you are getting the results you expect.