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.
Related
I have a MS Access Form with various controls organised into tabs.
There are some text fields among them, and I need the text field to update (that is, the vba to update them) when their tab is opened. The text fields aren't bound, the updating is a bit more customised.
I've tried the below code but it returns True for text fields that aren't on the visible tab
Private Sub TabCtl2_Change()
Dim Ctl As Control
For Each Ctl In Me.Form.Controls
If Ctl.ControlType = acTextBox Then
'Want to do stuff here
Debug.Print Ctl.Visible 'This is returning 'True' for all text fields
'not just the ones on the active tab.
Debug.Print Ctl.Name
End If
Next
End Sub
As far as I can see the Tab objects don't have a Controls collection or whatever you call it. Can someone help me how to loop through controls on a tab? I don't want to code it all in manually if I can help it.
The Page object in the Pages collection in the tabcontrol does have a Controls property.
This means, if you want to do something for all controls on the active page, you can use the following:
For Each control In Me.MyTabcontrol.Pages(Me.MyTabcontrol.Value).Controls
'Do Stuff
Next
I'm creating a form in MS Access with 10 butons simulatin a numeric keypad (only the values 0..9).
I would like to change the value of a combobox control in a subform each time I click on one of these butons. The combo box control is named "projectID"
I tried this but it is not the same as pressing the same key on a keypad.
Private Sub Buton3_Click()
Call Me.frmServDedicacion_Subformulario.Form.projectID_KeyPress(51) 'Ansii code for 3
end sub
I put this procedure as keypress event in order to verifiy the combobox method is executed, and it does (msgbox is ok) but the combobox doesn't receive the KeyAscii value.
Public Sub projectID_KeyPress(KeyAscii As Integer)
MsgBox Chr(KeyAscii)
End Sub
This looks like a problem referring to a control on a sub form from the main form. I still have trouble getting this right so I use a cheat sheet:
http://access.mvps.org/access/forms/frm0031.htm
I created a main form called main and put 10 buttons named button0 - button9 on the form and I dragged a form called mysubform onto the main form to create a subform. mysubform has a textbox named projectID. Then just set the click event to button0 to:
Private Sub button0_Click()
Me!mysubform.Form!projectID = 0
End Sub
Don't forget similar click events for buttons 1-9
some things that may be helpful:
! is the bang operator see:
Bang Notation and Dot Notation in VBA and MS-Access
by default, when you drag a form to create a subform control on another form, access gives the subform control the same name as the dragged form. so here mysubform refers to the subform control and not the original form used to make the subform.
Then .Form gets the form wrapped by the subform control.
I hope this answers your question
I have a page in a multi page form which takes input from a text box and check box and adds this into a multi column list box below it when a submit button I clicked. I then want the user to be able to select a row in the list box and display the contents in the text box and check box for editing.
I can add multiple text box and check box values into the list box using the submit button, but it does not select a row when I click on the list box item. It just does nothing. It looks like the focus is not being transferred.
Would really appreciate it if someone could give me some ideas or guidance on how I may solve this? The code for the two actions are:
Private Sub cmdaddcontrol_Click()
If Not txtbox_Ctrl_Desc = "" Then 'check for input into text box
ctrl_listbox.AddItem 'add items to list box
ctrl_listbox.List(ctrl_list_count, 0) = ctrl_list_count + 1 'add row number in list box column
ctrl_listbox.List(ctrl_list_count, 1) = txtbox_Ctrl_Desc.Value 'set list box column to text box contents
If Not chkbox_ctrl = False Then 'check if check box is selected then insert appropriate value into listbox column
ctrl_listbox.List(ctrl_list_count, 2) = "Y"
Else
ctrl_listbox.List(ctrl_list_count, 2) = "N"
End If
ctrl_list_count = ctrl_list_count + 1 'increment listbox row counter
txtbox_Ctrl_Desc = "" 'reset text box to blank
chkbox_ctrl = False 'reset check box to blank
Else
MsgBox "You have not enetered anything in the control box" 'error message if no control description in text box
End If
End Sub
Private Sub ctrl_listbox_Click()
Dim i As Integer
'find the selected list item
i = ctrl_listbox.ListIndex
ctrl_listbox.Selected(i) = True
'add the values to the text and check boxes above the list box
txtbox_Ctrl_Desc.Value = ctrl_listbox.Column(1, i)
If Not ctrl_listbox.Column(3, i) = " Y" Then
chkbox_ctrl.Value = True
Else
chkbox_ctrl.Value = False
End If
End Sub
After finding the cause of the issue in the comment chain of the question, I'd like to persist the solution here as an answer for the people that might come across the question in the future:
Make sure that the .Enabled and .Locked properties of the misbehaving ActiveX control are set correctly. (True if the control should allow manipulation/activation by the user at runtime. False if you want to deny the user interaction with the control.)
Verify that the event procedure has the correct name. Maybe you changed a controls name? The correct naming scheme for event procedures is controlName_eventName(), e.g. ListBox1_Click(). An empty _click() procedure is generated when you select Show code in the control's context menu in Design Mode.
Although seemingly trivial, sometimes simple details escape our attention - even more so in complex projects. It's often helpful to have someone from outside the project have look at your problem. In their innocent ignorance of your project's inner workings, they might just be able to ask the right questions that lead to a quick solution.
Longtime viewer, first time question asker.
I'm currently working with UserForms within MS Word and have a particular form that can have up to 20 different labels and accompanying textboxes with varying texts. I have all but the first hidden while not in use, however I would like the next label and text box to become visible following input in the previous textbox. So if you enter data (anything) in the first textbox, the next label and text box will become visible. Does this make sense? I've seen other responses here suggest using AfterUpdate() rather than Change() or Click() but can't figure out how to use any of them. I would share my code but at this point I don't have any code to share, other than my labels and textboxes are lblField1 txtField1, lblField2 txtField2...
Any suggestions?
I would suggest using Change event, when using AfterUpdate you need to leave you TextBox for a while to fire the event. If you have only one TextBox visible there is nothing to move to. If you have more TextBoxes you would need to move back to fire AfterEvent and I don't think this is what you expect.
So, double click wherever on your userform and add the following code in code area:
Private Sub txtField1_Change()
txtField2.Visible = True
lblField2.Visible = True
End Sub
Next, add next portion for next textbox:
Private Sub txtField2_Change()
txtField3.Visible = True
lblField3.Visible = True
End Sub
And so on, if only you have an order in controls name you just need to change numbers in the end of control names.
Background:
I am trying to place a label in Ms-Access that is being used as a button over a combo box. The user will select from the combo-box list and if they want to erase their selection they can click on the label to clear the selection.
Question:
Is it possible to get the label to show above the combo? It seems like the label is being sent behind the combo even though I specifically send it to the from etc...
Instead of creating the overlaying label to clear the selection, I would create an actual button. You will stack the button and the combo box on top of eachother in design mode, but set the button visibility to "No" in the format properties. Let's say you call the combo box "cmbSelect" and the clear button "cmdClear", use the following to show the button after the combo box is selected:
Private Sub cmbSelect_AfterUpdate
Me.cmdClear.Visible = True
End Sub
The following code will then clear the data from your table after the button is clicked:
Private Sub cmdClear_Click()
DoCmd.SetWarnings False
'Deletes record from your table
Dim Delete As String
Delete = "DELETE * FROM [TableName] WHERE (([TableName].KeyField)='" & KeyField & "')"
DoCmd.RunSQL Delete
DoCmd.SetWarnings True
End Sub
You could also have the form requery by running a requery on each field instead of using the delete string. Then you could build code for the button "after update" that makes the button invisible again and allows you to select a new entry from the combo box. There's a lot of possibility, but this should get you started. Let me know if you need any more explanation or help.