Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Im just plain confused - simple solution needed to a simple request 2

Status
Not open for further replies.

Kenny2003

Technical User
Dec 29, 2002
53
GB
Is there a simple or plain way of doing what I want. To me, in my mind, what I want to do is really simple..

I have a form that displays records based on one flat table. Each record could have an associated jpeg image. The image is stored outside on the db and the table stores links to the images in a field called Image1.

This is what I want to do:

If the control on the form called Image1 is displaying a jpeg for the current record then I want access to hide 3 other controls.
If control Image1 does not have a jpeg to display then I want Access to hide the control Image1 but show the 3 controls it was hiding.

Now I know this is not the correct syntax but it may serve to show what I am trying to do in the simplist terms.

If Image1 has jpeg Then
Image1.visible = True
ctrl1.visible = False
ctrl2.visible = False
ctrl3.visible = False

Else (if not?)
Image1.visible = False
ctrl1.visible = True
ctrl2.visible = True
ctrl3.visible = True



Is what I am trying to do available in these simple terms ?

Thank you again

Kenny
 
You could try the following in the form's on Current event

Presuming Image1 to be Null if empty ....

If Not IsNull(Image1) Then
Image1.visible = True
ctrl1.visible = False
ctrl2.visible = False
ctrl3.visible = False
Else
Image1.visible = False
ctrl1.visible = True
ctrl2.visible = True
ctrl3.visible = True
End If

Hope this helps.
 
and if a control [blue]has the focus[/blue] when you try to hide?

Calvin.gif
See Ya! . . . . . .
 
Hi Earthandfire,

Thanks for the reply and suggestion - I appreciate it.

I tried your code and Access just hides all the controls regardless of if there is a image or not. I have tried various different ways of phrasing the code but I can not get it to work.

In case you may be able to shed further light on what I am doing wrong I include the code I am using below.

Thank you again for your help.

Kenny

Private Sub Form_Current()
If Not IsNull(Image1) Then
Me.Image1.Visible = True
Me.txtPicture.Visible = False
'ctrl2.Visible = False
'ctrl3.Visible = False
Else
Me.Image1.Visible = False
Me.txtPicture.Visible = True
'ctrl2.Visible = True
'ctrl3.Visible = True
End If

End Sub
 
Hey ya again Aceman,

You seem to be popping up all over this forum, nice to see.

I dont understand what your post here ment "and if a control has the focus when you try to hide? "

What do you mean by this ?

Thanks

Kenny
 
Earthandfire,

Hi again,

Forgive my ignorance but I do not know what you mean by this "UnaffectedControl.SetFocus before the If statement???"

I am not that experienced in Access and VB but I am trying to learn, can you explain please.

Thank you,

Kenny
 
Kenny2003 . . . . .

[purple]You can't hide a control while it has the focus[/purple] (an error will be raised). I was just tickling [blue]earthandfire[/blue] to circumvent this in the code . . .

Calvin.gif
See Ya! . . . . . .
 
Kenny, AceMan was having a go at me. If one of the controls that you are trying to make invisible had the focus, Access would get rather angry. My reply simply meant that you will no doubt have other controls on the form that you will not be making invisible - therefore on the line immediately above If, pick a suitable control and set the focus to it.

As far as the problem is concerned, it may be better to test against txtPicture (which presumably has the filename for the picture). Try changing the If statement to:

If Trim(Nz(txtPicture,"")) = "" Then
..
..

What this does is:
1) If txtPicture Is Null it is converted to an empty string
2) If txtPicture has any leading or trailing spaces they are removed
3) Tests what is left to see if it is an empty string.

Hopefully this will do the trick.

By the way, if you don't have a suitable control to which you can set the focus, put and unbound textbox on the form and set its height and width as small as you can and the bordercolor to transparent, and position it at 0, 0. Then you can set the focus to this text box, but the user will not see it.
 
AceMan, it was a deliberate mistake to see if you were watching. At least that's my excuse and I'm sticking to it. [smile]
 
Thanks guys for the posts and tips, I will try them out later today after work.

Thank you again

Kenny
 
The 1st line after the ELSE should do the trick to ensure no errors arise when trying to disable the control due to it having the focus. Make sure to chage the "SomeOtherControl" to a valid control name.

Private Sub Form_Current()
If Not IsNull(Image1) Then
Me.Image1.Visible = True
Me.txtPicture.Visible = False
'ctrl2.Visible = False
'ctrl3.Visible = False
Else
Me.SomeOtherControl.SetFocus
Me.Image1.Visible = False
Me.txtPicture.Visible = True
'ctrl2.Visible = True
'ctrl3.Visible = True
End If

End Sub
 
Godofhell, what would then happen if txtPicture had the focus and there was an image? This is why focus should be relocated before any of the affected controls are made invisible or disabled.

 
Guys,

I just wanted to let you know that it all works now and it's thanks to you guys.

Thank you.

Not only that, I have learnt so much too - a nice bonus!

Thanks again,

Regards,

Kenny
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top