place a varible into a field

semry

Registered User.
Local time
Today, 14:15
Joined
Aug 5, 2012
Messages
22
I'm trying to get data from the last record change it and then place it into a new record.

I've tried the following and I can get the data and change it but I can't get it into a new record

Function AddRec()
DoCmd.OpenTable "OBCImages", acViewNormal, acEdit
DoCmd.GoToRecord , "", acLast
ValLocNum = DLast("LocNum", "OBCImages") + 1
MsgBox (ValLocNum) ' to see if it took
DoCmd.GoToRecord , "", acNewRec
LocNum = ValLocNum
DoCmd.Save

End Function
 
What you need is DMax() not DLast().

What's your reason for not using the AutoNumber data type anyway? And you should be using a form for manipulating records and not doing it directly on the table.
 
Thanks but that didn't do it. I haven't done this since DBaseIV.
I want to assign a file location for medical images. I have two fields. a Box number and file number. I want to reset the File number each time we start a new box.
 
Note that vbaInet said...
you should be using a form for manipulating records
...which is indeed the easiest way, but you can also open a recordset, or use an SQL action query.

A table doesn't simply expose it's fields for update as identifiers in VBA, which seems to be what you are trying to do here.
Code:
[COLOR="Green"]'These are just two identifiers in VBA...[/COLOR]
LocNum = ValLocNum

HTH,
Mark
 
Thanks All,
I've tried Forms and Queries and it is best way to go
 

Users who are viewing this thread

Back
Top Bottom