PDA

View Full Version : Access VBA help - runtime error 2465



GLawes
04-29-2013, 01:56 PM
Hi I am a novice VBA user and would be very grateful for your help with a small problem. I am wanting to lookup a name (FirstName) from a table called "Contacts" with the contact being based on a field within the current form called "fldTemp". The value "FirstName" i wish to return to the form in a field called "fldAddress".
I get a Run-time eror '2465' - MS office Access can't find the field '|' referred to in your expression.

Any help would be greatly appreciated.

Private Sub cmbAddressTo_AfterUpdate()
Dim strSalutation As String
'The folowing added today -
Dim strFirstName As String
Dim strLastName As String
Dim strAddressName As String
Dim strAdress01 As String
Dim strAddress02 As String
Dim strAddress03 As String
Dim strAddress04 As String
Dim strAddress05 As String
Dim intProjID As Double

Dim cnn As ADODB.Connection
Dim cmd As ADODB.Command
Dim rst As ADODB.Recordset
Dim strSQL3 As String

intProjID = Me.fldTemp

Set rst = New ADODB.Recordset

rst.ActiveConnection = CurrentProject.Connection
rst.CursorType = adOpenStatic
Set cmd = New ADODB.Command
cmd.CommandText = "Select * from Contacts Where [ContactID] = Me.fldTemp"

strFirstName = [FirtstName]


Me!fldAddress.Value = strFirstName