Changing Combobox to text box

M

Marco Brilo

Hi I have a form where users have options buttons to choose betweeen edit
mode and view only mode. When the view mode is chosen, I have a script that
will disable my combo boxes and hide certain buttons etc, but when they
choose edit mode, they the combo boxes and text boxes become enabled and
unlocked allowing the user to make changes to the data.
So here's my question, how do I change the combo box to a text box when the
user is in view mode so that they aren't likely to click on the field to see
a drop down of values, and when they come back to edit mode, change the text
box to a combo box again. I've pasted code below tha I am currently using.
Thanks
Marco


'************************************ VIEW DATA
************************************************************

If Me.Mode.Value = 2 Then
Me.DataEntry = False
Me.AllowEdits = False
Me.Search_Area_ID
For Each Control In Form.Controls
'MAIN FORM
With Control
Select Case .ControlType
Case acTextBox
.Visible = True
.Locked = True
.BackStyle = 0
.SpecialEffect = 0
.BorderStyle = 1
.BorderColor = RGB(255, 255, 255)
Case acComboBox
.Visible = True
.Locked = True
.BackStyle = 0
.SpecialEffect = 0
.BorderStyle = 1
.BorderColor = RGB(255, 255, 255)
Case acCommandButton
.Visible = True
End Select
End With
Next Control


Forms!Field_Data.Form!OBSERVER.Visible = True
For Each Control In Forms!Field_Data.Form!OBSERVER.Form.Controls
'OBSERVER SUBFORM
With Control
Select Case .ControlType
Case acTextBox
.Locked = True
.BackStyle = 0
.SpecialEffect = 0
.BorderStyle = 1
.BorderColor = RGB(255, 255, 255)
Case acComboBox
.Locked = True
.BackStyle = 0
.SpecialEffect = 0
.BorderStyle = 1
.BorderColor = RGB(255, 255, 255)
End Select
End With
Next Control
Forms!Field_Data.Form!OBSERVATION.Visible = True
For Each Control In
Forms!Field_Data.Form!OBSERVATION.Form.Controls 'OBSERVATION SUBFORM
With Control
Select Case .ControlType
Case acTextBox
.Locked = True
.BackStyle = 0
.SpecialEffect = 0
.BorderStyle = 1
.BorderColor = RGB(255, 255, 255)
Case acComboBox
.Locked = True
.BackStyle = 0
.SpecialEffect = 0
.BorderStyle = 1
.BorderColor = RGB(255, 255, 255)
End Select
End With
Next Control


Me.AllowAdditions = False
Me.Cmd_Create_Table.Visible = False
Me.Option28.Enabled = True
Me.cmd_Open_Select_Record.Visible = False
Me.NavigationButtons = True
Me.cltAddNewRecord.Visible = False


'************************************ EDIT DATA
************************************************************


ElseIf Me.Mode.Value = 1 Then
lngRecToEdit = Me.Survey_ID.Value
Me.DataEntry = False

For Each Control In Form.Controls
'MAIN FORM
With Control
Select Case .ControlType
Case acTextBox
.Visible = True
.Locked = False
.BackColor = RGB(255, 255, 255)
.BackStyle = 1
.SpecialEffect = 2

Case acComboBox
.Visible = True
.Locked = False
.BackColor = RGB(255, 255, 255)
.BackStyle = 1
.SpecialEffect = 2
Case acCommandButton
.Visible = True
End Select
End With
Next Control


Forms!Field_Data.Form!OBSERVER.Visible = True
For Each Control In Forms!Field_Data.Form!OBSERVER.Form.Controls
'OBSERVER SUBFORM
With Control
Select Case .ControlType
Case acTextBox
.Locked = False
.BackColor = RGB(255, 255, 255)
.BackStyle = 1
.SpecialEffect = 2

Case acComboBox
.Locked = False
.BackColor = RGB(255, 255, 255)
.BackStyle = 1
.SpecialEffect = 2
End Select
End With
Next Control

Forms!Field_Data.Form!OBSERVATION.Visible = True
For Each Control In
Forms!Field_Data.Form!OBSERVATION.Form.Controls 'OBSERVATION SUBFORM
With Control
Select Case .ControlType
Case acTextBox
.Locked = False
.BackColor = RGB(255, 255, 255)
.BackStyle = 1
.SpecialEffect = 2

Case acComboBox
.Locked = False
.BackColor = RGB(255, 255, 255)
.BackStyle = 1
.SpecialEffect = 2
End Select
End With
Next Control

Me.NavigationButtons = False
Me.cltAddNewRecord.Visible = False
Me.cmd_Open_Select_Record.Visible = True
Me.Cmd_Create_Table.Visible = True
Me.Filter = "SURVEY_ID = " & lngRecToEdit
Me.FilterOn = True
 
T

Tom van Stiphout

On Tue, 18 Sep 2007 05:58:02 -0700, Marco Brilo

I would personally never go through this effort, but if you really
want to, you'll have to have two controls, a dropdown and a textbox,
and show/hide as needed.
Assuming a pretty standard 2-column dropdown (ID, Description), the
expression for the textbox ControlSource could be:
=SomeDropdown.Column(1)

-Tom.
 
M

Marco Brilo

Thanks Tom,

that's what I was afraid of, it seems like such a simple task - I don't know
why there's no object already created for it? I think I'll just leave them
as combo boxes as I have many of them.
Marco
 
G

George Nicholson

Why not just set Enable = False and Locked = True? That prevents the
dropdown from functioning but otherwise preserves the appearance of the
control. If you want to hide the dropdown arrow, you can create a small
rectangle the same color as your form background that will cover the arrow
and then toggle it's Visible property as appropriate.

HTH,
 
M

Marco Brilo

Hi George
"Why not just set Enable = False and Locked = True? "
Thats a great suggestion except I want my users to have the ability to right
click on a field and do a filter. However now that I think about it I
suppose I could get them used to the 'filter by form' icon.
Thanks again!
Marco
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top