PDA

View Full Version : Solved: Changing combo box to text box in access 2003 using vba



smiler2505
04-29-2007, 03:25 PM
If Me.NewRecord = True Then

Me.cmbCNum.Locked = False
Me.cmbSNum.Locked = False
Me.cmbCNum.Enabled = True
Me.cmbSNum.Enabled = True

If Me.cmbCNum.ControlType = acTextBox Then
Me.cmbCNum.SetFocus
DoCmd.RunCommand acCmdChangeToComboBox
End If
If Me.cmbSNum.ControlType = acTextBox Then
Me.cmbSNum.SetFocus
DoCmd.RunCommand acCmdChangeToComboBox
End If

Else

If Me.cmbCNum.ControlType = acComboBox Then
Me.cmbSNum.SetFocus
DoCmd.RunCommand acCmdChangeToTextBox
End If
If Me.cmbSNum.ControlType = acComboBox Then
Me.cmbSNum.SetFocus
DoCmd.RunCommand acCmdChangeToTextBox
End If

Me.cmbCNum.Locked = True
Me.cmbSNum.Locked = True
Me.cmbCNum.Enabled = False
Me.cmbSNum.Enabled = False

End If


What I want to do is change the combo box to a text box, and vice versa, depending if the form is on a new record or not. The rest of the code works, but the part for changing the type of box doesn't. It doesn't work if I use, for example,


If Me.cmbSNum.ControlType = acComboBox Then
Me.cmbSNum.ControlType = acTextBox
End If

either.

Help?
Allow Design Changes is set to all views.

omocaig
04-30-2007, 10:19 AM
I think you may find it easier to stack a combobox on top of the textbox and then use your code to hide one or the other. That's how I do it anyway.

hth,
Giacomo

geekgirlau
05-01-2007, 11:17 PM
Just a thought, but perhaps this is something that can only be changed in design view. which means that you won't be able to do it on adding a new record. I'd run with Giacomo's hide option myself.

smiler2505
05-03-2007, 11:20 AM
I think you may find it easier to stack a combobox on top of the textbox and then use your code to hide one or the other. That's how I do it anyway.

hth,
Giacomo

this is the solution I already had! Thanks anyway, I just wondered if there was a 'cleaner' way to do it. It's obviously a function access needs if more than one person wants it!