simple question about saving a record on an unbound form

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I've got an unbound form pulling data from a small table. The table has the
following fields among others:

emp# <--primary key, indexed unique, not nullable, integer, does not
auto-increment
Firstname
Lastname
homeaddress
homecity
homestate
homezip


Here's my save function as it is currently. I intend to add error handling
later and so forth.

----------------------------------------------------------------------------------------------
dim cnn as new adodb.connection
dim rst as new adodb.recordset

cnn.open me.controls("xprovider") & me.controls("xdatasource")
rst.open "Select * from tblfsrinfo where emp# = " & me![emp#], cnn,
adOpenKeyset, adLockOptimistic

rst!emp# = me.emp#
rst!Firstname = me.firstname
rst!Lastname = me.lastname
rst!HomeAddress = me.HomeAddress
rst!HomeCity = me.HomeCity
rst!HomeState = me.HomeState
rst!HomeZip = me.HomeZi
----------------------------------------------------------------------------------------------

For some reason it doesn't seem to want to save the record if I include the
emp# field. It gives me the following error message: "Item cannot be found
in the collection corresponding to the requested name or ordinal."

If I comment out the line that says: rst!emp# = me.[emp#] then it saves the
record just fine. Excluding any changes to the emp# field of course.

But I want to be able to change the emp#, but I also want to ensure that the
value is unique and that all related records are updated too.

is it possible that it's choking on cascade updates somewhere?
 
Oops, In my previous post I forgot to include the rst.update line in my
example code. My question still remains though. What's the deal with my
emp# field that does not allow me to save any changes to it.
 
Your problem comes from the symbol #. Put [] around it:

rst![emp#] = me.[emp#]

or:
rst ("emp#") = me.[emp#]
 
Back
Top