Using Inpuit form and recordset to update Access table

Private Sub Command27_Click()
     Dim db As DAO.Database
     Dim rs As DAO.Recordset
     
     Set db = CurrentDb
     Set rs = db.OpenRecordset("tbl_StaffEval", dbOpenTable)
     
     rs.AddNew
     rs.Fields("ProviderID") = Me.List33.ItemSelected.Column(0).Value
     
     
     rs.Update
     
     rs.Close
     
     Set rs = Nothing
     
 End Sub

I using the code above to take the input for a ListBox with 4 columns and updating a table within the database.

The user selects one record from the List Box and clicks a Command Button to add a new record to the table.

I am getting an error Object Undefined on the line:

rs.Fields("ProviderID") = Me.List33.ItemSelected.Column(0).Value

The first column of data in the List Box is the ProviderID.

Thanks

Glen
GPSPOWAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Rey Obrero (Capricorn1)Commented:
try changing this

rs.Fields("ProviderID") = Me.List33.ItemSelected.Column(0).Value

with

rs!ProviderID=me.list33


what is the rowsource of the listbox "list33" ?
what is the bound column of the listbox?
0
GPSPOWAuthor Commented:
The "List33" list box row source is a table of physicians, "DMisProviders".  I have only selected the ones that have an Active Flag of "Y" and I have selected 4 columns from the table to display in the ListBox:

ProviderID
Name
SpecialtyID
Specialty

The form user picks a line from the ListBox to be added to the table "tbl_StaffEval"

I will eventually bring in more fields, but I just want to test this on the first list box bound column (ProviderID)

Thanks

Glen
0
mbizupCommented:
Are you dealing with a multi select list box:

Dim varItem
For Each varItem In Me.List33.ItemsSelected
rs.Fields("ProviderID")  = Me.List33.Column(0, varItem)
rs.Fields("SomeOtherField")  = Me.List33.Column(1, varItem)
rs.Fields("YetanotherField")  = Me.List33.Column(2, varItem)
rs.movenext

Next varItem

Open in new window


If the listbox does NOT have multi select enabled, then simply:

rs.Fields("ProviderID")  = Me.List33.Column(0)
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
GPSPOWAuthor Commented:
Thanks
0
Dale FyeCommented:
GPSPOW,

I think mbizup forgot the

rs.AddNew     'Between lines 2 and 3

and

rs.Update      'Between lines 5 and 6

lines in that block of code.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Access

From novice to tech pro — start learning today.