473,462 Members | 1,333 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Keith - Advice on code

Hi Keith, below is my code to hide the boxes and txt and button for 3
people, is there a shorter way to write this ?

Private Sub Form_Current()
If LastName = "Franz" Then
Me!Supplier1.Visible = False
Me!Supplier2.Visible = False
Me!Supplier3.Visible = False
Me!Supplier4.Visible = False
Me!Supplier5.Visible = False
Me!Label56.Visible = False
Me.AddSupplierBuy.Visible = False
ElseIf LastName = "Davis" Then
Me!Supplier1.Visible = False
Me!Supplier2.Visible = False
Me!Supplier3.Visible = False
Me!Supplier4.Visible = False
Me!Supplier5.Visible = False
Me!Label56.Visible = False
Me.AddSupplierBuy.Visible = False
ElseIf LastName = "Von Patow" Then
Me!Supplier1.Visible = False
Me!Supplier2.Visible = False
Me!Supplier3.Visible = False
Me!Supplier4.Visible = False
Me!Supplier5.Visible = False
Me!Label56.Visible = False
Me.AddSupplierBuy.Visible = False
Else
Me!Supplier1.Visible = True
Me!Supplier2.Visible = True
Me!Supplier3.Visible = True
Me!Supplier4.Visible = True
Me!Supplier5.Visible = True
Me!Label56.Visible = True
Me.AddSupplierBuy.Visible = True
End If

End Sub

Tempy

*** Sent via Developersdex http://www.developersdex.com ***
Nov 13 '05 #1
10 1283
"Tempy" <an*******@devdex.com> wrote in message
news:m%*************@news.uswest.net...
Hi Keith, below is my code to hide the boxes and txt and button for 3
people, is there a shorter way to write this ?

Private Sub Form_Current()
If LastName = "Franz" Then
Me!Supplier1.Visible = False


You could wrap them all up using "or"s:

If LastName = "Franz" or LastName = "whatever" ... etc

Regards,
Keith.

PS - probably best not to address your postings to an individual :o)
Nov 13 '05 #2
"Tempy" <an*******@devdex.com> wrote in message
news:m%*************@news.uswest.net...
Hi Keith, below is my code to hide the boxes and txt and button for 3
people, is there a shorter way to write this ?

Private Sub Form_Current()
If LastName = "Franz" Then
Me!Supplier1.Visible = False
Me!Supplier2.Visible = False
Me!Supplier3.Visible = False
Me!Supplier4.Visible = False
Me!Supplier5.Visible = False
Me!Label56.Visible = False
Me.AddSupplierBuy.Visible = False
ElseIf LastName = "Davis" Then
Me!Supplier1.Visible = False
Me!Supplier2.Visible = False
Me!Supplier3.Visible = False
Me!Supplier4.Visible = False
Me!Supplier5.Visible = False
Me!Label56.Visible = False
Me.AddSupplierBuy.Visible = False
ElseIf LastName = "Von Patow" Then
Me!Supplier1.Visible = False
Me!Supplier2.Visible = False
Me!Supplier3.Visible = False
Me!Supplier4.Visible = False
Me!Supplier5.Visible = False
Me!Label56.Visible = False
Me.AddSupplierBuy.Visible = False
Else
Me!Supplier1.Visible = True
Me!Supplier2.Visible = True
Me!Supplier3.Visible = True
Me!Supplier4.Visible = True
Me!Supplier5.Visible = True
Me!Label56.Visible = True
Me.AddSupplierBuy.Visible = True
End If

End Sub

Tempy

You could structure this by splitting it into two lumps - something like:

Private Sub Form_Current()
Select Case LastName
Case "Franz", "Davis", "Von Patow": ShowControls False
Case Else: ShowControls True
End Select
End Sub

Private Sub ShowControls(blnVisible As Boolean)
Me!Supplier1.Visible = blnVisible
Me!Supplier2.Visible = blnVisible
Me!Supplier3.Visible = blnVisible
Me!Supplier4.Visible = blnVisible
Me!Supplier5.Visible = blnVisible
Me!Label56.Visible = blnVisible
End Sub

Nov 13 '05 #3
Private Sub ShowControls(blnVisible As Boolean)
Dim I as Integer
dim strFieldName as string

For I = 1 to 5
strFieldName = "Supplier" & I
Me(strFieldName).Visible = blnVisible
Next I
Me!Label56.Visible = blnVisible
End Sub
Hank Reed

Nov 13 '05 #4
"Hank" <ha********@aol.com> wrote in message
news:11********************@g14g2000cwa.googlegrou ps.com...
Private Sub ShowControls(blnVisible As Boolean)
Dim I as Integer
dim strFieldName as string

For I = 1 to 5
strFieldName = "Supplier" & I
Me(strFieldName).Visible = blnVisible
Next I
Me!Label56.Visible = blnVisible
End Sub
Hank Reed

You've just made it one line longer
Nov 13 '05 #5

"Justin Hoffman" <j@b.com> wrote in message
news:d7**********@nwrdmz01.dmz.ncs.ea.ibs-infra.bt.com...
"Hank" <ha********@aol.com> wrote in message
news:11********************@g14g2000cwa.googlegrou ps.com...
Private Sub ShowControls(blnVisible As Boolean)
Dim I as Integer
dim strFieldName as string

For I = 1 to 5
strFieldName = "Supplier" & I
Me(strFieldName).Visible = blnVisible
Next I
Me!Label56.Visible = blnVisible
End Sub
Hank Reed

You've just made it one line longer


....and that's without the Me.AddSupplierBuy.Visible which has been left out
Nov 13 '05 #6
Justin Hoffman wrote:
"Justin Hoffman" <j@b.com> wrote in message
news:d7**********@nwrdmz01.dmz.ncs.ea.ibs-infra.bt.com...
"Hank" <ha********@aol.com> wrote in message
news:11********************@g14g2000cwa.googlegrou ps.com...
Private Sub ShowControls(blnVisible As Boolean)
Dim I as Integer
dim strFieldName as string

For I = 1 to 5
strFieldName = "Supplier" & I
Me(strFieldName).Visible = blnVisible
Next I
Me!Label56.Visible = blnVisible
End Sub
Hank Reed

You've just made it one line longer


...and that's without the Me.AddSupplierBuy.Visible which has been left out


Yes, but its so much more elegant. ;-)
If he had 10 controls, I could have been a hero.
You are absolutely right of course, but I find the approach useful when
changing the properties of multiple controls.
Hank

Nov 13 '05 #7
Hank wrote:
Private Sub ShowControls(blnVisible As Boolean)
Dim I as Integer
dim strFieldName as string

For I = 1 to 5
strFieldName = "Supplier" & I
Me(strFieldName).Visible = blnVisible
Next I
Me!Label56.Visible = blnVisible
End Sub You've just made it one line longer


...and that's without the Me.AddSupplierBuy.Visible which has been left out


Yes, but its so much more elegant. ;-)
If he had 10 controls, I could have been a hero.
You are absolutely right of course, but I find the approach useful when
changing the properties of multiple controls.


I prefer enumerating controls and checking the tag property:

dim c as Access.control

for each c in access.controls

if c.controltype = actextbox then

if c.tag = "Supplier" then c.visible = false

end if

next

This works well in forms with very many controls and a lot of processes
going on. It's not as efficient, of course as Justin's code, but it
sure is a lot easier to maintain if you are making a lot of changes.
--
Tim http://www.ucs.mun.ca/~tmarshal/
^o<
/#) "Burp-beep, burp-beep, burp-beep?" - Quaker Jake
/^^ "Whatcha doin?" - Ditto "TIM-MAY!!" - Me
Nov 13 '05 #8
Justin Hoffman wrote:
"Hank" <ha********@aol.com> wrote in message
news:11********************@g14g2000cwa.googlegrou ps.com...
Private Sub ShowControls(blnVisible As Boolean)
Dim I as Integer
dim strFieldName as string

For I = 1 to 5
strFieldName = "Supplier" & I
Me(strFieldName).Visible = blnVisible
Next I
Me!Label56.Visible = blnVisible
End Sub
Hank Reed


You've just made it one line longer


And here the same thing with 2 lines removed, making it one line
shorter, and then even adding the AddSupplierBuy.Visible it is still
one line shorter:

Private Sub ShowControls(blnVisible As Boolean)
Dim I as Integer

For I = 1 to 5
Me("Supplier" & I).Visible = blnVisible
Next I
Me!Label56.Visible = blnVisible
AddSupplierBuy.Visible = blnVisible
End Sub

The number of suppliers would then be irrelevant.

Nov 13 '05 #9
Thanks all for the input and sorry for the late reply.

Tempy

*** Sent via Developersdex http://www.developersdex.com ***
Nov 13 '05 #10
"DenBorg" <de******@yahoo.com> wrote in message
news:11**********************@g14g2000cwa.googlegr oups.com...
Justin Hoffman wrote:
"Hank" <ha********@aol.com> wrote in message
news:11********************@g14g2000cwa.googlegrou ps.com...
> Private Sub ShowControls(blnVisible As Boolean)
> Dim I as Integer
> dim strFieldName as string
>
> For I = 1 to 5
> strFieldName = "Supplier" & I
> Me(strFieldName).Visible = blnVisible
> Next I
> Me!Label56.Visible = blnVisible
> End Sub
> Hank Reed


You've just made it one line longer


And here the same thing with 2 lines removed, making it one line
shorter, and then even adding the AddSupplierBuy.Visible it is still
one line shorter:

Private Sub ShowControls(blnVisible As Boolean)
Dim I as Integer

For I = 1 to 5
Me("Supplier" & I).Visible = blnVisible
Next I
Me!Label56.Visible = blnVisible
AddSupplierBuy.Visible = blnVisible
End Sub

The number of suppliers would then be irrelevant.


Alright already! I was only teasing about the length.

Nov 13 '05 #11

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Andy Dingley | last post by:
I've just started on a new project and inherited a huge pile of XSLT (and I use the term "pile" advisedly !) It runs at glacial speed, and I need to fix this this. Platform is MSXML 4 / ASP ...
11
by: ma740988 | last post by:
I'm perusing a slide with roughly 12 bullets spread across 3 pages. Each bullet reflects 'advice'. I'm ok with all but 1 bullet, more specifically the bullet that states: " Avoid the STL unless...
6
by: strvariant | last post by:
Our company contracted with an outside consultant over a year ago to build a complex database application. The end product was put into production over nine months ago. Since then it has been...
6
by: | last post by:
I am starting out my transition from classic asp to .NET and was hoping some advice could be offered on using Webmatrix to do my initial small asp-like, xml and flash embedded projects. ...
13
by: Immanuel Goldstein | last post by:
Obtained under the Freedom of Information Act by the National Security Archive at George Washington University and posted on the Web today, the 74-page "Information Operations Roadmap" admits that...
13
by: Alan Silver | last post by:
Hello, MSDN (amongst other places) is full of helpful advice on ways to do data access, but they all seem geared to wards enterprise applications. Maybe I'm in a minority, but I don't have those...
7
by: John Paul | last post by:
I'm thinking of building an e-commerce site in php. Anyone got any advice in building one? What is the best way to implement a payment system? Are any legal issues involved? Thanks,
232
by: robert maas, see http://tinyurl.com/uh3t | last post by:
I'm working on examples of programming in several languages, all (except PHP) running under CGI so that I can show both the source files and the actually running of the examples online. The first...
26
by: Charlie Gordon | last post by:
Keith Thompson wrote this by private email: I've open an account with motzarella.org, and your last post does not show up there either. As a matter of fact, your messages show up on a very...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.