Basic VBA Question

Gener

Registered User.
Local time
Today, 15:29
Joined
Jul 27, 2012
Messages
14
Hello, I have an Access sheet that have three fields: InitialLevel, ID, and ID2. InitialLevel is changeable, ID is an autonumber, and ID2 is a changeable text field. I have a program that asks for ID and then locates it and adds one to the InitialLevel.
Code:
Option Compare Database

Sub AddToInventory()
Dim tb As DAO.Recordset
Dim I As Integer
I = 1
Do Until I = 2
On Error GoTo Canceled
Set tb = CurrentDb.OpenRecordset("Select InitialLevel from Inventory where ID2 = " & InputBox("Enter Item ID"))
If tb.EOF = False Then	
tb.Edit
tb!InitialLevel = tb!InitialLevel + 1
tb.Update

End If
tb.Close
Loop
Canceled:
End Sub

However, if I change ID to ID2, it prompts me and then when I press OK it stops the program. Anyone have any idea why this happens? BTW, the integer "I" is so it will simply loop.

Thanks!
 
I found the problem, the ID2 column could only be numbers. Thanks.
 

Users who are viewing this thread

Back
Top Bottom