Multiple Arguments with Property Let statement

  • Thread starter Thread starter Steven Lyday
  • Start date Start date
S

Steven Lyday

I am writing my first Class Module and using the Property
Statement for the first time. I have NOT had a problem
with Property Let and Property Get utilizing one (1)
argument. The problem is when I ADD a second (2) argument.
All of the avilable documentation describe the use of
multiple arguments. Unfortunately none of the examples
utilize more than one (1) arguement.

The WORKING code is a Write Only property (No Get Pair)
that sucessfully selects the designated field in the
current record:
========================================
(1) Called by:
Dim curTbl As CStdTableR_W_DAO
Set curTbl = New CStdTableR_W_DAO

curTbl.LetFieldData = ("Accountnumber")
========================================
========================================
Public Property Let LetFieldData(ByVal strFieldName As String)
' This Property Sets the Value of the Specified Field in
the Current Rec

Dim mcurDB As DAO.Database
Dim mrst As DAO.Recordset
Dim fld As DAO.Field

Set mcurDB = CurrentDb()
Set mrst = mcurDB.OpenRecordset("T-Transactions")

mrst.MoveFirst

For Each fld In mrst.Fields
If fld.NAME = strFieldName Then
' .... Res for Code to write Data

Exit For
End If
Next

End Property
====================================================
(2)I then add 'ByVal strFieldData as String' to the
property declare statement to include the variable for the
field data.

Public Property Let LetFieldData(ByVal strFieldName As
String, ByVal strFieldData as String)
====================================================
(3)I Comment out the calling statement.

'curTbl.LetFieldData = ("Accountnumber", "1234567890")

The code compiles successfully.

====================================================
(4) I remove the comment from the calling statement &
recompile.
====================================================
curTbl.LetFieldData = ("Accountnumber", "1234567890")

Error = "Compile Error Expected )" Error occurs at the comma.

-----------------------------------------------------
curTbl.LetFieldData = "Accountnumber", "1234567890"

Error = "Compile Error Expected end of statement" Error
occurs at the comma.

======================================================
5. When I type in the calling statement, When Intellisense
appears, it only identifies the first arguement.

I would appreciate an direction provided!

TIA and Re,

Steven Lyday
 
If you're trying to pass a field name and a value to set that field to, you
need to declare both parameters:

Public Property Let LetFieldData(ByVal strFieldName As String, varFieldValue
As Variant)

(If you know that all of the fields are of a particular data type, you can
use that data type instead of Variant. I used Variant to be able to handle
any type of data)

You call it as:

curTbl.LetFieldData("Accountnumber") = "1234567890"

Rather than looping through all the fields in the recordset until you come
to the correct one, why not just use:

mrst.Fields(strFieldName).Value = varFieldValue

Use On Error Resume Next to handle misspelled field nams.
 
Many thanks Doug,

Both the call statement and the field value write
recommendation work perfectly! The calling statement format
was "Exactly" what I was looking for. I had struggled with
it for going on a day and I do not know how I would have
finally figured it out on my own.

Regards,

Steven Lyday
 
Back
Top