Make button visible/invisible

pd06498

Registered User.
Local time
Today, 19:25
Joined
Dec 30, 2003
Messages
80
I am trying to get a command button to become either visible or not visible dependant upon whether there is data in a list box. I can get the button to disappear but it wont reappear.

I am using the following code:

Code:
If IsNull(Me.InspectionDate.Column(0)) Then
    Me.RecordHistory.Visible = False
Else
    Me.RecordHistory.Visible = True
End If

The list box is set to view only, that is it is locked and does not receive focus or tab stop.

Thanks in advance.
 
Try:

Code:
If IsNull(Me.InspectionDate.Column(0)) Or Me.InspectionDate.Column(0) = vbNullString Then
 
If column(0) is the bound column you don't need to refer to it
 
Mile-O

Thanks for the reply.
I still get the same problem. My form is set to go to a new record when it opens, and the offending command button is not visible, however when I navigate back through previous records where the InspectionDate contains information which should make the command button become visible, it doesn't.

The bound column is Column(1).

Any other ideas?
 
Is the code in the Form_Current sub?
 
Mile-O / Rich

I have this code in the Form On Current property, but still get the same problem. I have placed entire code for this Form below.

Code:
Private Sub Action_BeforeUpdate(Cancel As Integer)

If Action.Value = 1 Then
    Me.Archive.Visible = True
    Me.DateDestroyed.Visible = False
    Me.DateMoved.Visible = False
    Me.MovedTo.Visible = False
End If

If Action.Value = 2 Then
    Me.Archive.Visible = False
    Me.DateDestroyed.Visible = False
    Me.DateMoved.Visible = True
    Me.MovedTo.Visible = True
End If

If Action.Value = 3 Then
    Me.Archive.Visible = False
    Me.DateDestroyed.Visible = True
    Me.DateMoved.Visible = False
    Me.MovedTo.Visible = False
End If

End Sub

Private Sub EndDate_AfterUpdate()
    Me.DestructionYear = Year(Me.EndDate) + ([Retain] + 1)
End Sub


Private Sub Form_Current()
If IsNull(Me.InspectionDate.Column(1)) Or Me.InspectionDate.Column(1) = vbNullString Then
    Me.RecordHistory.Visible = False
Else
    Me.RecordHistory.Visible = True
End If

    Me.Officer = Me.IssuedTo.Column(1) & " " & Me.IssuedTo.Column(2) & " " & Me.IssuedTo.Column(3)
    Me.Retain = Me.Item.Column(2)
    Me.InspectionDate.Requery

If Action.Value = 1 Then
    Me.Archive.Visible = True
    Me.DateDestroyed.Visible = False
    Me.DateMoved.Visible = False
    Me.MovedTo.Visible = False
End If

If Action.Value = 2 Then
    Me.Archive.Visible = False
    Me.DateDestroyed.Visible = False
    Me.DateMoved.Visible = True
    Me.MovedTo.Visible = True
End If

If Action.Value = 3 Then
    Me.Archive.Visible = False
    Me.DateDestroyed.Visible = True
    Me.DateMoved.Visible = False
    Me.MovedTo.Visible = False
End If

End Sub


Private Sub Form_Open(Cancel As Integer)
  DoCmd.GoToRecord , , acNewRec
  Me.Item.SetFocus
  
End Sub


Private Sub IssuedTo_AfterUpdate()
    Me.Officer = Me.IssuedTo.Column(1) & " " & Me.IssuedTo.Column(2)

End Sub

Private Sub Item_AfterUpdate()
    Me.Retain = Me.Item.Column(2)
End Sub

Private Sub Previous_Click()
On Error GoTo Err_Previous_Click

    DoCmd.GoToRecord , , acPrevious

Exit_Previous_Click:
    Exit Sub

Err_Previous_Click:
    MsgBox Err.Description
    Resume Exit_Previous_Click
    
End Sub
Private Sub Next_Click()
On Error GoTo Err_Next_Click

    DoCmd.GoToRecord , , acNext

Exit_Next_Click:
    Exit Sub

Err_Next_Click:
    MsgBox Err.Description
    Resume Exit_Next_Click
    
End Sub
Private Sub Add_Click()
On Error GoTo Err_Add_Click

    DoCmd.GoToRecord , , acNewRec

Exit_Add_Click:
    Exit Sub

Err_Add_Click:
    MsgBox Err.Description
    Resume Exit_Add_Click
    
End Sub
Private Sub Close_Click()
On Error GoTo Err_Close_Click


    DoCmd.Close

Exit_Close_Click:
    Exit Sub

Err_Close_Click:
    MsgBox Err.Description
    Resume Exit_Close_Click
    
End Sub

'Private Sub Inspection_History_Click()
'On Error GoTo Err_Inspection_History_Click

    'Dim stDocName As String
    'Dim stLinkCriteria As String

    'stDocName = "frmInspectionDate"
    
   ' stLinkCriteria = "[InspectionID]=" & Me![Inspection]
    'DoCmd.OpenForm stDocName, , , stLinkCriteria

''Exit_Inspection_History_Click:
    'Exit Sub

'Err_Inspection_History_Click:
   ' MsgBox Err.Description
   ' Resume Exit_Inspection_History_Click
    
'End Sub
Private Sub Inspections_Click()
On Error GoTo Err_Inspections_Click

    Dim stDocName As String

    stDocName = "qryInspectItem"
    DoCmd.OpenQuery stDocName, acNormal, acEdit

Exit_Inspections_Click:
    Exit Sub

Err_Inspections_Click:
    MsgBox Err.Description
    Resume Exit_Inspections_Click
    
End Sub
Private Sub RecordHistory_Click()
On Error GoTo Err_RecordHistory_Click

    Dim stDocName As String

    stDocName = "rptRecordInspectionHistory"
    DoCmd.OpenReport stDocName, acPreview

Exit_RecordHistory_Click:
    Exit Sub

Err_RecordHistory_Click:
    MsgBox Err.Description
    Resume Exit_RecordHistory_Click
    
End Sub
 
What you should do is put it in a seperate sub called something like UpdateButtons.

I would remove your record selector buttons and add in your own controls - just create a command button and choose record navigation - you will need to add buttons for first, last, next and previous. In the code for each of these you should do the code to move records which will be entered automatically by VBA then you should call UpdateButtons. This will go off and it will hide/make visible the buttons based on what is in the list box.


You may also need to add a Create New button from the record operations - and add the call to UpdateButtons there. How does information get put into this list box if they can't get access to change anything in it? Is it done automatically when you add a date or something in somewhere? If so then you will want to call UpdateButtons immediately after you have updated that ListBox. Without seeing the database its kinda hard to guess but i hope this goes some way to help you.

Private Sub UpdateButtons
If IsNull(Me.InspectionDate.Column(0)) Then
Me.RecordHistory.Visible = False
Else
Me.RecordHistory.Visible = True
End If
End Sub
 
ifstar

Thanks for the reply.

I already have control buttons to navigate and have disabled the record selector buttons. I also have a 'home made' add and close button.

When you mention creating a separate sub, where and how do I do that.
 
Can you post a small example of your database as I can't help but feel that things are being over-complicated?
 
pd06498 said:
ifstar

Thanks for the reply.

I already have control buttons to navigate and have disabled the record selector buttons. I also have a 'home made' add and close button.

When you mention creating a separate sub, where and how do I do that.

Just copy and paste what i stuck in at the end of my post - just add it into the code for that form - just stick it right at the very bottom - that means you can call that code from this form only.
Fot the button you have already made - UpdateButtons at the end - and that will go off and jump into the UpdateButtons sub and it will do the check there (basically whenever you navigate through records it will run off and check if it should be displaying that button or not).

Hope this works for you.

Iain
 
One other thing - if you want to check if there's data in the ListBox then stop sayin IsNull and ask if it's ListCount = 0
 

Users who are viewing this thread

Back
Top Bottom