Help with lstbox vba code

I am trying to move information from selected items in a list box into a table. I keep receiving errors when I try to run the code.

This is what I have:

Private Sub btnAddSelected_Click()

Dim frm As Form
Dim ctl As Control
Dim intCounter As Integer

Dim db As DAO.Database
Dim rst As DAO.Recordset

Set frm = Forms!("frm_Act_Enter")
Set ctl = frm![lstPrevRpts]

Set db = CurrentDb
Set rst = rst.OpenRecordset("Act_SubTo_Date")


If ctl.ItemsSelected.Count > 0 Then
    For intCounter = 0 To ctl.ItemsSelected.Count - 1
        rst.AddNew
            rst("ActID") = ctl.Column(5, intCounter)

        rst.Update
    Next intCounter
End If

rst.Close
Set rst = Nothing



End Sub

Open in new window


My error is "Type-declaration character does not match declared data type."


This may very well be one of those cases where I just missed something tiny, but I can't see it.

When the debugger runs, it highlights this line:

Set frm = Forms!("frm_Act_Enter")

Open in new window

MeginAsked:
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.

Gustav BrockCIOCommented:
It should read:

Set frm = Forms("frm_Act_Enter")

/gustav
0
MeginAuthor Commented:
That error isn't happening now, but I have a new error.

"Run-Tim error '91': Object variable or With block variable not set." The line highlighted is:
Set rst = rst.OpenRecordset("Act_SubTo_Date")

Open in new window


I looked up the error and it appears to derive from an incorrect or missing Set statement. But I don't know which one I am missing. I thought I had set everything I need. I double checked that the name of the table was right.
The other thing I saw with that error was that it can be associated with With statements, but I don't have that in my code. Does it also associate with If statements?

Thank you for the help!
0
Gustav BrockCIOCommented:
Yes. That should read:

Set rst = db.OpenRecordset("Act_SubTo_Date")

/gustav
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
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

MeginAuthor Commented:
ugh!
 
Now that is working! No more errors. Thank you very much for that.

Now I have another problem with the code not adding any information to my ActID field in the table.

Should I post this as a new question, or can I follow up in this thread.

Again, no errors. The code just isn't adding the actid to the table. It is creating a new, blank record.
0
Gustav BrockCIOCommented:
Insert a debug line and perhaps add .Value:

        rst.AddNew
            Debug.Print intCounter, ctl.Column(5, intCounter)
            rst("ActID").Value = ctl.Column(5, intCounter)
        rst.Update

to see what it finds.

/gustav
0
MeginAuthor Commented:
The immediate window shows "0         Null"

I don't know what this means.

Now the code doesn't add anything.

You know what? You answered the original question. I am going to close this question and submit the new problem as a new question.

Thank you for all your help!
0
Gustav BrockCIOCommented:
You are welcome!

/gustav
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.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.