• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 286
  • Last Modified:

ADODB Connection Error - Access 2007

Hi All,

A newbie to Access 2007, I am having issues with inserting records into a table due to connection type mismatches.

Could someone please help me arrange the correct syntax for the following procedure?

CF
Public Function createCustomer(uTxtNewCompanyName As String, uTxtLastName As String, uTxtFirstName As String, uTxtEmailAddress As String, _
uTxtJobTitle As String, uTxtBusinessPhone As Long, uTxtHomePhone As Long, uTxtMobilePhone As Long, uTxtFaxNumber As Long, uTxtAddress As String, _
uTxtCity As String, uTxtStateProvince As String, uTxtZIPPostalCode As Long, uTxtCountryRegion As String, uTxtWebPage As String) As Long
    'Creates a new customer in system
    'RETURNS the new customer id

    Dim rs As New ADODB.Recordset
    Dim Conn As Connection
    Set Conn = CurrentProject.Connection
    Dim strSQL As String
    Dim vCreationDTS As Date
    Dim vLastUpdateDTS As Date
        
    vCreationDTS = Now
    vLastUpdateDTS = Now

    strSQL = "INSERT INTO TBL_CONTACTS (Company, LastName, FirstName, EmailAddress, JobTitle, BusinessPhone, HomePhone, MobilePhone, " & _
    "FaxNumber, Address, City, StateProvince, PostCode, CountryRegion, WebPage, Attachments, Notes, CreationUserID, CreationDTS) " & _
    "SELECT '" & uTxtNewCompanyName & "' AS Company, '" & uTxtLastName & "' AS LastName, '" & uTxtFirstName & "'" & _
    " AS FirstName, '" & uTxtEmailAddress & "' AS EmailAddress, '" & uTxtJobTitle & "' AS JobTitle, " & uTxtBusinessPhone & _
    " AS BusinessPhone, " & uTxtHomePhone & " AS HomePhone, " & uTxtMobilePhone & " AS MobilePhone, " & uTxtFaxNumber & " " & _
    " AS FaxNumber, '" & uTxtAddress & "' AS Address, '" & uTxtCity & "' AS City, '" & uTxtStateProvince & "' AS StateProvince, " & uTxtZIPPostalCode & "" & _
    " AS PostCode, '" & uTxtCountryRegion & "' AS CountryRegion, '" & uTxtWebPage & "' AS WebPage, '" & vCreationDTS & "' AS CreationUserID"
    rs.Open strSQL, Conn, adOpenKeyset, adLockOptimistic
    Set rs = Nothing

    strSQL = "SELECT @@IDENTITY FROM TBL_CONTACTS"
    rs.Open strSQL, Conn, adOpenKeyset, adLockOptimistic

    createCustomer = rs(0)
    Set rs = Nothing

End Function

Open in new window

0
creativefusion
Asked:
creativefusion
1 Solution
 
peter57rCommented:
What error/problem are you having?
0
 
McOzCommented:
Change this:

 
Dim rs As New ADODB.Recordset 
    Dim Conn As Connection 
    Set Conn = CurrentProject.Connection 
    Dim strSQL As String 
    Dim vCreationDTS As Date 
    Dim vLastUpdateDTS As Date

Open in new window


To this:

 
Dim rs As New ADODB.Recordset 
    Dim Conn As ADODB.Connection 
    Set Conn = CurrentProject.AccessConnection 
    Dim strSQL As String 
    Dim vCreationDTS As Date 
    Dim vLastUpdateDTS As Date

Open in new window


And it should work.

Cheers,
McOz
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now