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

Copy Fields To New Record

Status
Not open for further replies.

rcorbett

Instructor
Nov 25, 2002
24
US

I have fields on my form titled Box# and Slot#. Each Box contains 81 slots for test tubes (Slot#). The below code shows how I am able to limit the entries to 81 – this works fine. Basically it assigns slot #’s between 1 and 81 depending on the last entry.

What I want to do is copy the previous Box# and Paste it in the same field on a new record – my code is: Me![Box#].DefaultValue = Me![Box#]. It is in the AfterUpdate event.

I have at least two issues happening: One, the Box# only copies itself to the new record if I have entered the Box# and then tabbed through the form and allow it to start a new record. If I open the DB and click the new record button it does not copy the last box #. Second Issue is this; the Slot# will not increment unless I retype the Box# in. Seems that I can get it to copy but when tabbing through the form it will not update the slot# unless I type the box # in.

Hope this makes sense -Thanks for any suggestions.


Private Sub Box__AfterUpdate()
Me![Box#].DefaultValue = Me![Box#]

Dim VarMaxSlot As Variant

VarMaxSlot = DMax("[Slot#]", "tblHLAFrozenSpecimenLog", "[Box#]=" & Me![Box#])
If VarMaxSlot = 81 Then
MsgBox ("Maximum number reached")
Me.Form.Undo
Cancel = True
ElseIf IsNull(VarMaxSlot) Then
Me![Slot#] = 1
Else
Me![Slot#] = VarMaxSlot + 1
End If

End Sub

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top