Auto-update

garrim

New member
Local time
Today, 19:47
Joined
Nov 15, 2010
Messages
2
Hi there friends. Let me start by giving a short background:

We ship containers to our customers.
Each container is given a unique number.
The container is returned to us when it's empty.
A customer can order one or many containers.
To keep track of this we have an Excel-sheet that is becoming hard to handle.

So...

I decided to try to make a nice little Access app, and so far I'm doing pretty fine. If it weren't for one little thing.

I ant to put in a textbox the number of containers this order have; '15'. Then when I hit the GO-button I'd love if a table could be updated with the container numbers, starting one up from the last and 14 more. So if the last was 2100 we'd have 2101, 2102...2015.

I think you understand and I'm really hoping you can help me out here. Thanx in advance.

/g
 
First add a button to your form and on the OnClick Event add the following code. But remember to use table and field names that apply to your database


Code:
Call AddContainersToOrder(Me.TxtContainersWanted)


Code:
Public Function AddContainersToOrder(IntContainers)

Dim nIndex As Integer     'Loop Counter
Dim NextId As Long        'Last Container Number

Dim Rs As DAO.Recordset
Set Rs = CurrentDb.OpenRecordset("TblContainers")

Rs.MoveLast
NextId = Rs("ContainerNumber")+1

For nIndex = 1 To InContainers

     Rs.AddNew
     Rs("ContainerNumber") = NextID
     Rs("...")
     etc
     Rs.Update

     NextID = NextID + 1

Next nIndex

Rs.Close
Set Rs = Nothing

End Function


The above function goes to your table and gets the last id and adds 1 to it. It then adds the new record and adds 1 to the nextid variable. It does this on a loop until it reaches the number of recrods to add.
 
Thank you ever so much for the quick reply. I will try this as once.

/g
 

Users who are viewing this thread

Back
Top Bottom