Code won't run

crann

Registered User.
Local time
Today, 02:37
Joined
Nov 23, 2002
Messages
160
Hi Everyone

Ok so I have been trying to get this code to work for ages but as a beginner keep getting lost.

I have a form that depending what is in a specific field will display a specific command button to another form.

I have read through and downloaded some of the following code

I have a field called: txtone which is auto populated from other code with either: Aspect Property Solutions Ltd or Conquer Ltd.

I want to display the command button: CmdViewResults when the field: txtone contains: "Aspect Property Solutions Ltd"

and I want to

display the command button: CmdViewResults1 when the field: txtone contains: "Conquer Ltd"

and obviously want the opposite not to appear so only ever one command button displayed on the form.

This is the code I have works OK for first cmd button but nothing happens on second:

thanks

Private Sub Form_Current()

If txtone = "Aspect Property Solutions Ltd" Then

Me.CmdViewResults.Visible = True
Else
Me.CmdViewResults.Visible = False


If txtone = "Conquer Ltd" Then

Me.CmdViewResults1.Visible = True
Else
Me.CmdViewResults1.Visible = False


End If

End If


End Sub
 
Try this
Code:
     If Me.txtone = "Aspect Property Solutions Ltd" Then
        Me.CmdViewResults.Visible = True
        Me.CmdViewResults1.Visible = False
    ElseIf Me.txtone = "Conquer Ltd" Then
        Me.CmdViewResults.Visible = False
        Me.CmdViewResults1.Visible = True
    End If
 
Thanks so much

So simple but couldn't see wood for trees.

Thanks again
 
Is this possible.

When txtone displays no text (for example when the main form first loads its blank.) That neither command button is displayed?

Thanks
 
Just put

Me.CmdViewResults1.Visible = False
Me.CmdViewResults.Visible = False

in the form load event
 
I'd use Sneuberg's code in a sub procedure and call it from the form load event. You can then call it from the After Update event as well.

Code:
      If Me.txtone = "Aspect Property Solutions Ltd" Then
        Me.CmdViewResults.Visible = True
        Me.CmdViewResults1.Visible = False
    ElseIf Me.txtone = "Conquer Ltd" Then
        Me.CmdViewResults.Visible = False
        Me.CmdViewResults1.Visible = True
     Elseif IsNull(Me.txtone]
          Reset_Fields
    End If
  
  
 Sub Reset_Fields
     Me.CmdViewResults1.Visible = False
    Me.CmdViewResults.Visible = False
 End Sub
 

Users who are viewing this thread

Back
Top Bottom