Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

expression with !

Status
Not open for further replies.

joeschoe

Programmer
Jan 13, 2002
67
0
0
IL
I don't understand the line I found in a sample program.
Can someone please interpret for me the line:
rs!Vfield = Vdata

It appears in the second last line of the sample code below.
Code:
Sub ADOXAddRecord(Tab_name As String, Vfield As Variant, Vdata As Variant)
Dim cat As New ADOX.Catalog
Dim tbL As New ADOX.Table
Dim arData() As String
Dim x As Integer, y As Integer
Dim i, j
Dim rs As ADOdb.Recordset
Set rs = New ADOdb.Recordset
Set cat.ActiveConnection = connDB
rs.Open "SELECT * FROM " & Tab_name & " Where 1=0", connDB, adOpenStatic, adLockOptimistic
rs.AddNew

rs!Vfield = Vdata 

rs.Update
 
Vfield should be the name of field in the opened table, which is assigned the value contained in the Vdata variable.

I'm assuming this gives an error, but it would nice if you'd said so, cause, since Vfield is passed to the sub, probably the following would work

[tt]rs.fields(Vfield).value = Vdata[/tt]

Though, I'd probably consider passing table name and the field name as string variables, and also the Vdata as appropriate datatype, perhaps also use an append query on the connection to insert in stead of opening a recordset too?

Roy-Vidar
 
Thanks for your quick reply.
So the ! means "assign value to"?

You are right, I did get an error
runtime error 3265
Item cannot be found in the collection corresponding to the requested name or ordinal

Do you have a sample code of what the append query would look like?
 
No, the bang (!) separates the object variable and a named member a collection, here it's default collection (fields collection). Having a field named "myfield" in the opened recordset "rs", one can refer to it in a number of ways, like for instance

[tt]rs!myfield
rs.fields("myfield")

dim strName as string
strName = "myfield"
rs.fields(strName)[/tt]

The equal sign, and what's on the right side of it, means "assign value to"

Roy-Vidar
 
Here's some further discussion of '!' thread222-717031
 
By the way, in the other thread that strongm mentions, a couple of people mention that bang notation is "super slow" for ADO field access. I can't put my finger on the thread right now where I tested this, but these two constructs
Code:
rs!myfield
rs("myfield")
run about the same, whereas
Code:
rs(intFieldOffset)
runs significantly faster, as strongm points out.

HTH

Bob
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top