VBA enabling text and combo box in MS Access - ms-access

I'd like to make a text box (Text28 hereafter) and a combo box (combo43 hereafter) enabled when another combo box (Combo26) takes the value "Resolved"
So this is the code, written in VBA, that should do that :
Private Sub Combo26_AfterUpdate()
If Combo26.Value = "Resolved" Then
Me.Text28.Enabled = True
Me.Combo43.Enabled = True
Else
Me.Text28.Enabled = False
Me.Combo43.Enabled = False
End If
End Sub
Unfortunatly, nothing happens when I try it. Would you have a idea ?
Thx

If you are pulling two columns as your row source (as indicated in your comment above), it looks like the first one that is displayed is the ID. You should target the second column to do your comparison, e.g.,
If Combo26.Column(1) = "Resolved" Then
...
That works for me!
Combo26.Column(0)
will give you the ID.

Related

MS Access VBA, efficient way to enable a button only after all required textboxes contains valid data

My code is working, but I just want to know if there is a more efficient way to achieve the same effect.
I have this layout in a form:
In my effort to foolproof the record creation process, I would like to have the "Save and Clear fields" button enabled only after all but the 'Comment' textbox/combobox contains some valid data.
The text/combo boxes are called txtBatteryID, cmbModelNumber, cmbChemistryType, txtSpecVoltage, txtSpecCapacity.
My code is as follow
Private Sub EnableSaveBtnCheck()
'this checks if the required fields contains valid data, if so, enables the save button.
If Me.btnSaveAndCLear.Enabled = False Then
If IsNull(txtBatteryID) = False And IsNull(cmbModelNumber) = False And IsNull(cmbChemistryType) = False And IsNull(txtSpecVoltage) = False And IsNull(txtSpecCapacity) = False Then
Me.btnSaveAndCLear.Enabled = True
End If
End If
End Sub
As you can see, I did the most straightforward way of using AND to combine all must-have conditions in an IF statement. This sub is called in After_Update() event of each text/combo box. Like this:
Private Sub cmbChemistryType_AfterUpdate()
Call EnableSaveBtnCheck
End Sub
My question, in the end, is: Is there a more efficient way to setup the condition "all text/combo box need to have something valid in them"? And is there a more elaborate way to check if the condition is met (something like a event on the form itself)?
Add the values of those 5 fields. If any of them is Null, the sum will be Null. So you only need call IsNull() once.
If IsNull(txtBatteryID + cmbModelNumber + cmbChemistryType + txtSpecVoltage + txtSpecCapacity) = False Then

Use checkbox to filter data

I want when the checkbox or button (both at the top of this screen) is checked, it does not show the items that are "Canceled" or "Received" in the Status column.
Items names:
status search box is called "S_Status"
status dropdown menu is called "Status"
the dropdown option is pulled from Query "N_Q_PlacingOrders_Status" which pulls from Table "N_T_Placing Orders_Status".
Checkbox name is "CheckBox"
I tried the code below but I know I am missing a couple things that I have not been able to find in other blogs/forums.
Private Sub CheckBox_Click()
If CheckBox = True Then
DoCmd.ApplyFilter , Status = True
If CheckBox = False Then
Exit Sub
End If
End If
End Sub
Looks like you were on the right track. Two things of note:
1) In the following code, these lines (If CheckBox = False Then |Exit Sub |End If) are basically pointless, unless you want the False to actually do something, its just extra fluff. Therefore, removing the secondary If statement is beneficial.
If CheckBox = True Then
DoCmd.ApplyFilter , Status = True
End If
2) Using filters in this situation may not be the easiest way to accomplish your goal. Try this:
If CheckBox = True Then
Status.RowSource = "SELECT * FROM N_Q_PlacingOrders_Status WHERE " & _
"Status NOT IN ('Recieved', 'Cancelled')"
End If
NOTE: It may need a modification to the SELECT statement, as required by the rows you are trying to pull (but I don't have that information).

MS Access: ComboBox Requery

I have a ComboBox which will display data which dependent on what has been entered in another ComboBox. The second ComboBox is not updating (showing) data in the dropdown after the first has been updated...
Company_Select_Combo is the first ComboBox. After a selection has been made in this combobox, Marketer_Select_Combo becomes visible on the form, and this query should reflect those marketers associated to the company selected in the first combo...
Help
Private Sub Company_Select_Combo_AfterUpdate()
If Company_Select_Combo > 0 Then
Company_Select_Combo.Enabled = False
Marketer_Select_Combo.Visible = True
Me.Marketer_Select_Combo.Requery
Else
Marketer_Select_Combo.Enabled = False
End If
End Sub
Let assume your "Marketer_Select_Combo" query includes:
Marketer_ID, Marketer_Name, and Company_ID
Then simply add the following statement to your SQL:
WHERE Company_ID = [Forms]![yourformname]![Company_Select_Combo]
This way, the elements should be limited to the chosen company. By calling the Requery/Recalc method as you did, it should work as intended.

Change the value of the Checkbox

I add a new line of data into the table through the form. On the form I also have checkbox which is also integrated into the table. Ticking the checkbox leads to getting a value of -1. Is it possible to change -1 into a user defined value such as 'x'?
Simple answer: No.
More complex answer: You can use a hidden bound field, an unbound checkbox, VBA and default values to make a checkbox that behaves just like a bound checkbox that returns a different value.
Consider two fields, myUnboundCheckbox and myBoundTextfield. myBoundTextfield holds "X" for True, "Y" for False.
myUnboundCheckbox is an unbound checkbox, myBoundTextfield is a hidden bound text field
Then you can use the following:
Private Sub myUnboundCheckbox_AfterUpdate()
If myUnboundCheckbox Then
myBoundTextfield = "X"
Else
myBoundTextfield = "Y"
End If
End Sub
Private Sub Form_Current()
myUnboundCheckbox = myBoundTextfield = "X"
End Sub

ms access vba code I can disable a field based on content of another field, but my code to re-enable is not working

I have a simple form where I have a field InstrumentTypes_ID and a field DGLenders_ID.
When InstrumentTypes_ID equals "Mortgage" or "Modification", I want DGLenders_ID to stay enabled, but any other value should make DGLenders_ID become disabled.
I have the following code in an AfterUpdate for the InstrumentTypes_ID textBox, which to me seems would be sufficient to get this effect (However, when testing, I can type in "Warranty Deed" (or anything that's not "Mortgage" or "Modification"), which disables the DGLenders_ID field, but if I go back and update it with "Mortgage" or "Modification", it won't re-enable that field):
Private Sub InstrumentTypes_ID_AfterUpdate()
Me.DGLenders_ID.Enabled = True
If Me.InstrumentTypes_ID = "Mortgage" Then
Me.DGLenders_ID.Enabled = True
ElseIf Me.InstrumentTypes_ID = "Modification" Then
Me.DGLenders_ID.Enabled = True
Else
Me.DGLenders_ID.Enabled = False
End If
End Sub
You should try to put your code in a subroutine and call it on the current event of the form and in the lost focus event of the field.