littleclayjar
Technical User
I have an Access table with the fields "Name" and "IDNum". I need to write a vba module that returns the corresponding "IDNum" when i input the "Name" into the InputBox. So far I have the code below, but it only returns the first "IDNum" record in the table for whatever "Name" I type in. What am I missing in the code below? Thanks!
Sub SupplierInfo()
Dim TableName As String
TableName = "tblSuppliers"
Dim SupplierDB As Database, SupplierTbl As Recordset
Set SupplierDB = DBEngine.Workspaces(0).Databases(0)
Set SupplierTbl = SupplierDB.OpenRecordset(TableName, dbOpenSnapshot)
Dim Ask As String
Dim Msg As String
Dim ID As String
Msg = "What is the name of the supplier?"
Ask = InputBox(Msg, "SupplierName")
ID = SupplierTbl!SupplierID
MsgBox "The Supplier ID is " & ID
End Sub
Sub SupplierInfo()
Dim TableName As String
TableName = "tblSuppliers"
Dim SupplierDB As Database, SupplierTbl As Recordset
Set SupplierDB = DBEngine.Workspaces(0).Databases(0)
Set SupplierTbl = SupplierDB.OpenRecordset(TableName, dbOpenSnapshot)
Dim Ask As String
Dim Msg As String
Dim ID As String
Msg = "What is the name of the supplier?"
Ask = InputBox(Msg, "SupplierName")
ID = SupplierTbl!SupplierID
MsgBox "The Supplier ID is " & ID
End Sub