Consulting

Results 1 to 4 of 4

Thread: Solved: Changing combo box to text box in access 2003 using vba

  1. #1

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

    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.
    Last edited by smiler2505; 04-29-2007 at 03:42 PM.

  2. #2
    VBAX Regular
    Joined
    Jan 2007
    Posts
    20
    Location
    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

  3. #3
    VBAX Master geekgirlau's Avatar
    Joined
    Aug 2004
    Location
    Melbourne, Australia
    Posts
    1,464
    Location
    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.

  4. #4
    Quote Originally Posted by omocaig
    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!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •