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 Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

invalid operation 1

Status
Not open for further replies.

samotek

Technical User
May 9, 2005
197
BG


CaN somebody help me find the error in my code ? I get the error "invalid operation" with the following line :

tdf.Fields("CustomerID") = 121



Public Function Test()
Dim dbs As DAO.Database
Dim rst As DAO.Recordset
Dim fld As DAO.Field
Dim tdf As DAO.TableDef

Set dbs = CurrentDb
Set rst = dbs.OpenRecordset("orders1", dbOpenDynaset)
Do While Not rst.EOF

rst.MoveNext
Set tdf = dbs.TableDefs("Orders1")

Set fld = tdf.Fields("CustomerID')
tdf.Fields("CustomerID") = 121

Loop

rst.Close
Set rst = Nothing
Set dbs = Nothing
End Function
 
What do you want to do with the tdf.Field object ?

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
I infer that you're trying to set the value of the customerID field to 121. You don't use a TableDef to do that. TableDefs allow you to set the properties of the field (i.e. the metadata) ... not the values that they contain. Try something like
Code:
Public Function Test()
    Dim dbs                         As DAO.Database
    Dim rst                         As DAO.Recordset
    Dim fld                         As DAO.Field
    Dim tdf                         As DAO.TableDef

    Set dbs = CurrentDb
    Set rst = dbs.OpenRecordset("orders1", dbOpenDynaset)
    With rst
        Do While Not .EOF

            .Edit
            ![CustomerID] = 121
            .Update
            .MoveNext
            
        Loop
        .Close
    End With
    
    Set rst = Nothing
    Set dbs = Nothing
End Function

Note however that the above will set the CustomerID field to have the value "121" for every record in the table.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top