Article ID: 113300
Article Last Modified on 10/11/2006
Declarations Section
Option Explicit
Function AddNewCust (CustomerID$, CompanyName$)
Dim MyDB As Database, MyTable As Recordset
Set MyDB = DBEngine.Workspaces(0).Databases(0)
' Trap any error that might occur.
On Error Resume Next
' Open table.
Set MyTable = MyDB.OpenRecordset("Customers", DB_OPEN_TABLE)
MyTable.AddNew ' Prepare new record.
MyTable("CustomerID")= CustomerID$ ' Set record key.
' NOTE: The above line should read MyTable("Customer ID")=
' CustomerID$ in version 2.0.
MyTable("CompanyName") = CompanyName$ ' Set company name.
' NOTE: The above line should read MyTable("Company Name")=
' CompanyName$ in version 2.0.
MyTable.Update ' Save changes.
MyTable.Close ' Close table.
' Return the error code.
AddNewCust = Err
End Function
This function returns 0 if successful; otherwise, a Microsoft Access
error number is returned. If a record in the Customers table already
exists with the specified Customer ID, error number 3022 is returned.
This error would return the following error message if it were not
trapped:
DatabaseName;SQL Select FunctionName(args) From None;
AddNewCustomer
chan=INITIATE("MSACCESS","NORTHWIND;SQL SELECT _
AddNewCust(""JOHNJ"",""John's Place"") FROM None;")
=ALERT(REQUEST(chan,"FirstRow"))
=TERMINATE(chan)
=RETURN()
The following is the equivalent Microsoft Excel Visual Basic
Sub procedure:
Sub AddNewCustomer()
Chan = DDEInitiate("MSACCESS", "NORTHWIND;SQL SELECT _
AddNewCust(""TADO"",""Tad's Place"") FROM None;")
Result = DDERequest(Chan, "FirstRow")
Msgbox str(result(1))
DDETerminate Chan
End Sub
The following is the equivalent Microsoft Word for Windows Word-
Basic macro:
Sub MAIN
var1$ = "JOHNJ"
var2$ = "John's Place"
qt$ = Chr$(34) ' create the quote character
Funct$ = "AddNewCust(" + qt$ + var1$ + qt$ + "," + qt$ +_
var2$ + qt$ + ")"
Chan = DDEInitiate("MSACCESS", "NORTHWIND;SQL SELECT " + _
Funct$ + " FROM None;")
Result$ = DDERequest$(Chan, "FirstRow")
MsgBox Result$
DDETerminate Chan
End sub
100167 ACC1x: How to Use DDE to Pass Information to MS Access 1.x
Additional query words: ddepoke
Keywords: kbinfo kbinterop kbprogramming KB113300