How to disable input in bound combobox using IME - vba

I am trying to find a way to disable IME input (Japanese) in a bound combobox control in MS access 2016 form.
The problem I am facing is that on a bound ComboBox control it will change to Hiragana even with IME mode set to disable, whilst on a non bound Combobox, setting IME mode to disable will prevent IME from changing to Hiragana which is the expected behavior.
My ultimate goal is to disable all kind of keyboard input to the target ComboBox either bound or unbound either with direct input or with IME.
I use the following code the block keyboard input (non IME) in the ComboBox, but this does not work with IME input, so I thought disabling IME is my only way achieve complete keyboard input prevention on the control.
Private Sub comboBox_KeyDown(KeyCode As Integer, Shift As Integer)
If KeyCode <> vbKeyTab And KeyCode <> vbKeyReturn And KeyCode <> vbKeyDelete And KeyCode <> vbKeyBack Then KeyCode = 0
End Sub
EDIT:
By bound control, I mean it has the property Control Source set

Related

How to increase indent in a list memo field of current line by using the tab key in MS Access?

I have a memo field in an MS Access database where I create notes. I often use bulleted lists in this note field that is displayed on a form with a large text box.
The MS Access default when tab key is pressed is to cycle to the next control, however when I'm editing a "note" (memo field type) text box making a bulleted or numbered list I want to indent that line.
I have been able to "catch" the tabkey and execute "IndentIncrease" from the commandbar object. ("Catching" the tab key required using the KeyPress event of the text box, and turning off tabstop on all objects in the form).
However, this indents the bottom line of the field, even if the cursor is in the middle somewhere. Using the mouse to click the "increase indent" button in the text formatting section of the Ribbon works fine and indents the intended line of the ribbon.
Is there any way to get my code to catch the tab key and indent the correct line of my memo field?
Private Sub tbNoteEditor_KeyPress(KeyAscii As Integer)
If KeyAscii = 9 Then
Application.CommandBars.ExecuteMso ("IndentIncrease")
End If
End Sub
In this case, you want the KeyDown Event, as opposed to KeyPress. KeyPress represents a character being typed, which is not always the case with Tab. KeyDown will grab any key. Also, if you are catching Tab to increase the indent level, you probably also want to catch Shift-Tab to decrease the indent level. And, you will not need to turn off TabStop all over your form. :)
Private Sub tbNoteEditor_KeyDown(KeyCode As Integer, Shift As Integer)
If KeyCode = 9 Then
If (Shift And acShiftMask) > 0 Then
Application.CommandBars.ExecuteMso ("IndentDecrease")
Else
Application.CommandBars.ExecuteMso ("IndentIncrease")
End If
KeyCode = 0
End If
End Sub

How do I make unbound controls writeable?

I have an MS Access 2013 database that I am porting all tables and queries to SQL Server. After unbinding the controls on a form, I am unable to make them editable.
The form I am working with has a combo box, and a text box that are loaded from ADODB recordsets populated with data returned from Stored procedures.
I have tried to make the controls (Combo box, and text box) editable by changing the "Locked" and "Enabled" properties, and I have set the form's AllowEdits to True, but I am unable to change the selected text in the combo box or change text in the text box.
Private Sub cboCombo_KeyDown(KeyCode As Integer, Shift As Integer)
Me.cboCombo.Locked = False
Me.cboCombo.Enabled = True
Select Case KeyCode
Case vbKeyTab, vbKeyPageUp, vbKeyPageDown, vbKeyEnd, vbKeyUp, vbKeyDown, vbKeyLeft, vbKeyRight, vbKeyHome, vbKeyExecute, vbKeyEscape
Case Else
DoCmd.CancelEvent
End Select
End Sub
I want to be able to make a selection, but when the program is running, the status text repeatedly says the form is read only.

In Access VBA how does one keep a textbox active and select all its contents after Enter key

In an Access form I am using a textbox to filter an unbound subform. I want to allow the end user to quickly perform quick sequential searches. After the Enter key is pressed to perform a first search, I want the cursor/focus to remain in the text box and the current search text to be selected. In this way the user can directly start entering a new query, replacing the old search text.
I tried the answers to this question, but due to the Enter key, the selection always gets lost:
The solution I came up with is to intercept the Enter key press. It is important to cancel the event, otherwise the Enter key will remove the selection.
Private Sub txtSearch2_KeyDown(KeyCode As Integer, Shift As Integer)
If KeyCode = vbKeyReturn Then
Call Search
If Len(Me.txtSearch2.Text & "") = 0 Then Exit Sub
Me.txtSearch2.SelStart = 0
Me.txtSearch2.SelLength = Len(Me.txtSearch2.Text)
DoCmd.CancelEvent
End If
End Sub

Enabling only one checkbox in a row in Access Multiple Item Form

I have a multiple item form, where most of the checkboxes are disabled unless the user checks the box before it.
Currently I'm using:
If Me.Field1 Then
Me.chxField2.Enabled = True
Else
Me.chxField2.Enabled = False
End If
But if I check the box, it enables the Field2 checkbox for all of them, I only want it to enable the checkbox for one particular row.
Is this possible to do? If it isn't, that's ok but I just had to ask.
Edit: Thanks to Erik I did this in the BeforeUpdate like he described, and it gives the effect I wanted:
Private Sub chxField2_BeforeUpdate(Cancel As Integer)
Cancel = Not Field1
chxField2.Undo
End Sub
Unfortunately, it's not (as far as I know).
On a continuous form, there's actually only one instance of each control. This means that you can't have one of those Field2 checkboxes enabled, and another disabled.
Things you can do:
Use the Checkbox_BeforeUpdate event to check if Field1 is checkded. If it isn't checked, then rollback the change:
Private Sub Field2_BeforeUpdate(Cancel As Integer)
Cancel = Not Field1
End Sub
Also, if you weren't using a checkbox, you would be able to use conditional formatting to give the control a "disabled look". Unfortunatlely, conditional formatting doesn't apply to checkboxes.

Ellipsis Textbox for VBA Userform File Select

I am trying to create a path selection user interface for an extensive VBA program I've been working on, but I can't seem to get the ellipsis textbox that I'd like. This is a very common feature, especially in option tables. This is an example of what I'd like to get, straight from the VBA Options panel:
I would LOVE to find a way to get the same functionality in a Userform. The only solution that I've found thus far is to use a combo box with the ellipsis arrow option enabled. However, there doesn't seem to be an apparent way to use the activation of the combo box arrow to run a dialog box, nor does there seem to be a way to make it look UNLIKE a combo box. Last resort I use a button below the text box, but I'd really prefer a less-bulky way of doing this.
Any solution would be greatly appreciated.
The only solution that I've found thus far is to use a combo box with
the ellipsis arrow option enabled. However, there doesn't seem to be
an apparent way to use the activation of the combo box arrow to run a
dialog box, nor does there seem to be a way to make it look UNLIKE a
combo box
Your suggestion does work, and it is surely less complex and more elegant than having two controls work together, Button + Textbox.
A Combo can achieve perfectly the desired feature, in the following way.
1) In design mode, set the button style to Ellipsis
DropButtonStyle = fmDropButtonStyleEllipsis
And eventually, make the ellipsis show up only when the combo is entered, by setting the design-time property:
ShowDropButtonWhen = ShowDropButtonWhenFocus
2) If needed, you can set other design-time properties to have some look and feel. The defaults look pretty good however.
3) Add the following handler to the parent userform. The snippet simulates the launching of a dialog and getting a new value or cancelling. It does not show any dropdown window. (but you still have control over that: if you want to show it according to some condition, you still can call the method ComboBox1.DropDown)
Private Sub ComboBox1_DropButtonClick()
' The following two lines avoid to call the routine twice, at entry and at exit
Static i As Integer
i = (i + 1) Mod 2: If i = 0 Then Exit Sub
With ComboBox1
s = InputBox("enter some text", , .Value) '<~~ simulates any dialog
If s <> "" Then .Value = s
SendKeys ("{Enter}") '<~~ to close immediately the dropdown window
End With
End Sub
Try it ;)
Not only do ComboBoxes have Drop Buttons, so do TextBoxes (as do Excel's RefEdit controls). Even though you can't access the Textbox's Drop Button at design time, you can do so at runtime. Using a textbox avoids having to deal with the dropped down list of a combobox.
Given a textbox named TextBox1, the following code will provide the desired ellipsis drop button:
Private Sub UserForm_Initialize()
With Me.TextBox1
.DropButtonStyle = fmDropButtonStyleEllipsis
.ShowDropButtonWhen = fmShowDropButtonWhenAlways
End With
End Sub
Then use the DropButtonClick event of the textbox to perform whatever action you want:
Private Sub TextBox1_DropButtonClick()
'' Code here to do what you need
End Sub
I have an extensive example at Alternative to Excel’s Flaky RefEdit Control that uses a textbox with a "Reduce" drop button to replicate the functionality of Excel's unreliable RefEdit controls.