Button Visible

alpapak

Registered User.
Local time
Today, 05:20
Joined
Apr 3, 2006
Messages
64
Hi,

I have a form(frmMain) which contain unbound buttons.
btn1, btn2, btn3, btn4, btn5, btn6, btn7, btn8, btn9, btn10

The form controls are:
CodeID, number
Code1, number
Code2, number

Each Code1 and Code2 contains numbers from 1-10...

tblCode
CodeId_,_Code1_,_Code2_
__1____,___4___,___8___
__2____,___7___,___9___
__3____,___2___,___6___
__4____,___3___,___7___
__5____,___2___,___6___


So, if the frmMain load and its CodeID is 4, the Code1=3 and Code2=7...
i want to make buttons from btn3 to btn7 visible=True... Hide the rest buttons...

Any ideas from where to start???
How to make the buttons between these two numbers visible???
 
Code so far:

Dim Number1 as string
Dim Number2 as string

Number1 = Code1
Number2 = Code2

How to convert Number1 to "btn" & Number1 and become a control???
 
When you say you want to make button 3 to 7, you mean buttons 3,4,5,6 and 7, right?

Here's one possible way:
Code:
Select case CodeID

Case 1
     me.btn1.visible = false
     me.btn2.visible = false
     me.btn3.visible = false
     me.btn4.visible = true
     me.btn5.visible = true
     me.btn6.visible = true
     me.btn7.visible = true
     me.btn8.visible = true
     me.btn9.visible = false
Case 2
     me.btn1.visible = false
     me.btn2.visible = false
     me.btn3.visible = false
     me.btn4.visible = false
     me.btn5.visible = false
     me.btn6.visible = false
     me.btn7.visible = true
     me.btn8.visible = true
     me.btn9.visible = true

{Additional Case Statements Here}
End Select
 
Thank you very much for your reply...

Yes, if the values are 3 - 7, i want mean btn3 - btn7...
But, i code with case is not a solution, becuse the 3 - 7 are values from the controls Code1 and Code2 for CodeID = 4...

The problem is that each CodeID will have different Code1 and Code2, according to the data that the user will write...

I am trying to convert the Code1 and Code2 to strings and then to make btn's...

Code so far:
Dim Number1 As String
Dim Number2 As String
Dim Number3 As String
Dim Number4 As String
Dim i As Integer

Number1 = Me.Code1
Number2 = Me.Code2
Number3 = Number2 - Number1
Number4 = "btn" & Number3

For i = 1 To Number3
ctrl = "btn" & Number3
Me![ctrl].Visible = False <==========Error: 2465
Number3 = Number3 + 1
Next i


How to convert Number1 to "btn" & Number1 and become a control???
 
Thxs for your reply...

Found it...

Code:

Sub AllShow()
Dim ctrlx As Control
Dim x As Integer
Dim Showx As String
For i = 1 To 10
Showx = "btn" & i
For Each ctrl In Me.Controls
If ctrl.ControlName = Showx Then
ctrl.Visible = True
End If
Next
Next
End SubPrivate Sub Form_Current()
SameCode
End Sub

Private Sub Form_Load()
SameCode
End Sub

Sub SameCode()
Dim Number1 As String
Dim Number2 As String
Dim Number3 As String
Dim Number4 As String
Dim ctrl As Control
Dim i As Integer

AllShow

Number1 = Me.Code1
Number2 = Me.Code2
Number3 = Number2 - Number1
Number4 = "btn" & Number1

For i = 1 To Number3
Number4 = "btn" & Number1 + i - 1
For Each ctrl In Me.Controls
If ctrl.ControlName = Number4 Then
ctrl.Visible = False
End If
Next
Next

End Sub

Is it possible to make a better code??? I will have around 150buttons...
 
Last edited:
How can i make it works in with continuous forms???

I tested the code in a form with 10buttons and works great...
But when i tried it with continuous forms all rows where the same...
How to make it works for each row...??
 
How can i make it works in with continuous forms???

I tested the code in a form with 10buttons and works great...
But when i tried it with continuous forms all rows where the same...
How to make it works for each row...??

Doing that sort of thing with a continuous form is going to be rather problematic, as the controls on all forms will be set to reflect the reality of the record that currently hold focus.

As you have discovered ;)
 

Users who are viewing this thread

Back
Top Bottom