Question Locked

Getting "Compile Error: Object required"

0 helpful
12 replies
Closed to new repliesThis discussion is closed. It stays readable, but it takes no new replies.

I have the follwing VBA code in an Access form to hide and unhide Combobox and Listbox; but I am getting a "Compile Error: Object required." I would appreciate anyone that could look at the code and tell me what I am doing wrong. If I need to post more info, let me know.

Public Sub cmbRptName_AfterUpdate()

Dim intLvlID As Integer

intLvlID = "Select LevelID From tblReports " & _
"WHERE ReportID = " & cmbRptName.Value
If IsNull(intLvlID) Then
Me.cmbRptName.Visible = True
Me.cmbSup.Visible = False
Me.lstAssociate.Visible = False
IfElse intLvlID = 1
Me.cmbSup.Visible = False
Me.lstAssociate.Visible = False
IfElse intLvlID = 2
Me.cmbSup.Visible = True
Me.lstAssociate.Visible = False
Else
Me.cmbSup.Visible = True
Me.lstAssociate.Visible = True
End If

Set intLvlID = Nothing

End Sub

12 replies

by wizard-09

The code in order for anyone to help you out with this, without the code we cant tell were it is going wrong.

by slayer_

int's are primitave data types and don't need to be set to nothing, set nothing is for objects, thus object required

by atorres

Thanks for the reply. I now getting a new error: Sub or Function not defined.

I am learning VB and I am now being chalenged in creating an app that pulls reports according to the level of the report. For instance, if the report level is Dept. or 1 then the supervisor combobox and the associates list will not show. They will only show if the report is for a sup or for an associate respectibly.

Thanks!

by wizard-09

Your not going to learn if you 1st don't resreach the problem and try and work it out for yourself, only as a last resort should you be asking for help other wise you wont really learn anything will you?

by atorres

You are right, t_mcnally_2001, and I am actually working the problem out myself and researching it. I found the problem with the previous error. I mispelled the ElseIf statement. Now this is my new revised code and I am getting a new error "Run-time error '94': Invalid use of Null"

Public Sub cmbRptName_AfterUpdate()

Dim intLvlID As Integer

intLvlID = cmbRptName.Column(4)

If IsNull(intLvlID) = True Then
Me.cmbRptName.Visible = True
Me.cmbSup.Visible = False
Me.lstAssociate.Visible = False
ElseIf intLvlID = 1 Then
Me.cmbSup.Visible = False
Me.lstAssociate.Visible = False
ElseIf intLvlID = 2 Then
Me.cmbSup.Visible = True
Me.lstAssociate.Visible = False
Else
Me.cmbSup.Visible = True
Me.lstAssociate.Visible = True
End If

End Sub

I appreciate any help. I just want to select a report name from the first combobox and the rest of the boxes to appear as needed.

Again thank you for any help!

by wizard-09

To see that you figured out the last error message, i was only saying that from a learning point of view.

I am not into VB so i can't help you on this but someone on the form will.

From what i see of the code and known nothing of the kind about it

If IsNull(intLvlID) = True Then

Its the onlu null i see in the code so this is the problem i think.

Bet that is off no help lol

by thumbsup2

You've defined your variable as an integer and integers are never NULL. So, your check for NULL of an integer type is an "Invalid Use".

by atorres

I am trying several options and researching. As I do this I am learning how to resolved other problems.

Thank you for your assistance. I got the null issue resolve, but the boxes are not hiden.

by slayer_

Because elseifs are damn confusing and somewhat glitchy in VBA

Select Case intLvlID
case 0
Me.cmbRptName.Visible = True
Me.cmbSup.Visible = False
Me.lstAssociate.Visible = False
Case 1
Me.cmbSup.Visible = False
Me.lstAssociate.Visible = False
Case 2
Me.cmbSup.Visible = True
Me.lstAssociate.Visible = False
Case Else
Me.cmbSup.Visible = True
Me.lstAssociate.Visible = True
End Select

by atorres

Thank you for the help. It definately worked. I had to make changes to the logic but it worked. Thanks again.

by slayer_

Be sure to thumbs up any posts that helped you so others can quickly determine the posts that will be helpful to them.

This discussion is closed to new replies.