Function WhatCustomer(CID) As String
Dim sSQL As String
Dim rst As ADODB.Recordset, cnn As ADODB.Connection, cmd As ADODB.Command
Const DBNAME = "H:\Attachmate\CustDat.mdb"
Set cnn = New ADODB.Connection
Set cmd = New ADODB.Command
Set rst = New ADODB.Recordset
cnn.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & DBNAME & ";Persist Security Info=False"
sSQL = "Select tblCustomers.PrimaryName from tblCustomers WHERE tblCustomers.ID=?"
With cmd
.CommandText = sSQL
.CommandType = adCmdText
.Prepared = True
.Parameters.Append .CreateParameter( _
"ID", _
adChar, _
adParamInput, _
7, _
CID)
.ActiveConnection = cnn
Set rst = .Execute
End With
On Error Resume Next
rst.MoveFirst
If Err.Number = 0 Then
WhatCustomer = rst(0)
Else
WhatCustomer = "NONE"
End If
rst.Close
cnn.Close
Set cmd = Nothing
Set rst = Nothing
Set cnn = Nothing
End Function