I'm getting an error in Access 2003 (Error: -2147217904: No value given for one or more required parameters)
I'm trying to get information from the access database and send it to Outlook 2003. But this error keeps coming up and I tried the stepping into. and Once it gets to the rst.Open line it skips down to the MsgBox line and then I get the error.
Function TransferContacts()
'Transfer contact records from Contacts to Outlook.
Dim rst As New ADODB.Recordset
Dim cnn As New ADODB.Connection
Dim appOutlook As New Outlook.Application
Dim ns As Outlook.Namespace
Dim fldContacts As Outlook.MAPIFolder
Dim itms As Outlook.Items
Dim objContactFolder As Object
On Error GoTo ErrHandler
Set cnn = CurrentProject.Connection
Set appOutlook = CreateObject("Outlook.Application")
Set ns = appOutlook.GetNamespace("MAPI")
Set fldContacts = ns.GetDefaultFolder(olFolderContacts)
Set itms = fldContacts.Items
'Prevent duplicate contacts in Outlook.
rst.Open "SELECT * FROM Lead_Generation_Contacts WHERE Transfered = 0", cnn, adOpenKeyset, adLockOptimistic
'Prevent error when recordset is empty, meaning there are no
'new contact records to transfer.
If rst.RecordCount = 0 Then
MsgBox "There are no new contact records to transfer", vbOKOnly, "Transfer stopped"
Exit Function
End If
rst.MoveFirst
Do While Not rst.EOF
Set objContactFolder = itms.Add("IPM.Contact")
With objContactFolder
.CustomerID = Nz(rst!ContactNo)
.FullName = Nz(rst!ContactOneFirstName & " " & ContactOneLastName)
.AssistantsName = Nz(rst!ContactTwoFirstName & " " & ContactTwoLastName)
.Notes = Nz(rst!Notes)
.HomePhone = Nz(rst!HomePhone)
.MobilePhone = Nz(rst!CellPhone)
.E -mail = Nz(rst!Email)
.HomeAddress = Nz(rst!Address)
.Managersname = Nz(rst!LenderAssignedTo)
.Created = Nz(rst!InitialDateProspected)
.Close olSave
End With
Set objContactFolder = Nothing
rst.Update "Transferred", -1
rst.MoveNext
Loop
Set cnn = Nothing
Set appOutlook = Nothing
Set ns = Nothing
Set fldContacts = Nothing
Set itms = Nothing
Exit Function
ErrHandler:
MsgBox Err.Number & ": " & Err.Description, vbOKOnly, "Error"
End Function
What am I doing wrong? I've been going crazy with this code for about a week now.


P.S. Also with the "Notes" field is there a way to append onto that field instead of writing over the code?
I'm trying to get information from the access database and send it to Outlook 2003. But this error keeps coming up and I tried the stepping into. and Once it gets to the rst.Open line it skips down to the MsgBox line and then I get the error.
Function TransferContacts()
'Transfer contact records from Contacts to Outlook.
Dim rst As New ADODB.Recordset
Dim cnn As New ADODB.Connection
Dim appOutlook As New Outlook.Application
Dim ns As Outlook.Namespace
Dim fldContacts As Outlook.MAPIFolder
Dim itms As Outlook.Items
Dim objContactFolder As Object
On Error GoTo ErrHandler
Set cnn = CurrentProject.Connection
Set appOutlook = CreateObject("Outlook.Application")
Set ns = appOutlook.GetNamespace("MAPI")
Set fldContacts = ns.GetDefaultFolder(olFolderContacts)
Set itms = fldContacts.Items
'Prevent duplicate contacts in Outlook.
rst.Open "SELECT * FROM Lead_Generation_Contacts WHERE Transfered = 0", cnn, adOpenKeyset, adLockOptimistic
'Prevent error when recordset is empty, meaning there are no
'new contact records to transfer.
If rst.RecordCount = 0 Then
MsgBox "There are no new contact records to transfer", vbOKOnly, "Transfer stopped"
Exit Function
End If
rst.MoveFirst
Do While Not rst.EOF
Set objContactFolder = itms.Add("IPM.Contact")
With objContactFolder
.CustomerID = Nz(rst!ContactNo)
.FullName = Nz(rst!ContactOneFirstName & " " & ContactOneLastName)
.AssistantsName = Nz(rst!ContactTwoFirstName & " " & ContactTwoLastName)
.Notes = Nz(rst!Notes)
.HomePhone = Nz(rst!HomePhone)
.MobilePhone = Nz(rst!CellPhone)
.E -mail = Nz(rst!Email)
.HomeAddress = Nz(rst!Address)
.Managersname = Nz(rst!LenderAssignedTo)
.Created = Nz(rst!InitialDateProspected)
.Close olSave
End With
Set objContactFolder = Nothing
rst.Update "Transferred", -1
rst.MoveNext
Loop
Set cnn = Nothing
Set appOutlook = Nothing
Set ns = Nothing
Set fldContacts = Nothing
Set itms = Nothing
Exit Function
ErrHandler:
MsgBox Err.Number & ": " & Err.Description, vbOKOnly, "Error"
End Function
What am I doing wrong? I've been going crazy with this code for about a week now.



P.S. Also with the "Notes" field is there a way to append onto that field instead of writing over the code?