Hey I have a checkbox that I want a textbox linked to that turns grey if the checkbox is not clicked. I have the code under the on click event on the checkbox and this works if the box is clicked the first time..... It allows the textbox to become enabled. But I want it to if the used accidently clicks the checkbox they can click off the checkbox and the textbox goes back grey again. Im not sure if I have the code on the wrong event for the checkbox or not. Thanks.
Private Sub FlightScheduleAffected_Click()
If IsNull(Me.FlightScheduleAffected.Value) Then
Me.TimeMOCCNotified.Enabled = False
Else
Me.TimeMOCCNotified.Enabled = True
End If
End Sub
The value of the checkbox should be true or false, it will never be null. You want your if statement to read
If Me.FlightScheduleAffected.Value Then
Me.TimeMOCCNotified.Enabled = True
Else
Me.TimeMOCCNotified.Enabled = False
End If
Related
I was wondering how I can define a combo box in a form where the user can select an option from the existing list, and if he can't find the desired option, a "add a new option" can be accessed which converts the combo box to a text box for writing the new option?
You can put a button next to the combo, for an 'add option' which is triggered when the combo 'not in list' event is hit - and the button then would call a popup form - or in your suggestion, changes the visibility of an overlayed text box that allows for entry. I suggest a popup form, however, because then you can validate the input for length, content, etc - and then once the form or text box is filled in - exiting the text box, or submitting the form would save to your table for the drop down, refresh the combo box source query, and assign the value. I do this in VBA alot with popups.
Sorry my bad english :-(
You can directly use the "On Not in List" event. Look at the examples at
https://learn.microsoft.com/en-us/office/vba/api/Access.ComboBox.NotInList
This is the scenario: A combobox called cb and a textbox called tb. Visible property of tb is false. Combobox and Textbox have the same data source. When you type a value that is not in the combobox list, that value goes to the textbox; when you finished editing textbox, it is hidden again.
Private Sub cb_NotInList(NewData As String, Response As Integer)
' Suppress error message and undo changes.
Response = acDataErrContinue
Me!cb.Undo
' Prompt user to verify they wish to add new value.
If MsgBox("Value is not in list. Add it?", vbOKCancel) = vbOK Then
Me!tb.Visible = True
Me!tb.Value = NewData
Me!tb.SetFocus
End If
End Sub
Private Sub tb_AfterUpdate()
' Hide again texbox
Me!tb.Visible = False
' Update combobox items
Me!cb.Requery
End Sub
I inserted the following VBA code to my textbox in a form. It only works if i type something then delete what i typed. If i go to the next box, then the error message comes out. Is there any way to require the textbox is filled out?
Private Sub master_bill_a_BeforeUpdate(Cancel As Integer)
If IsNull(Me.master_bill_a) Then
Cancel = True
MsgBox "You must enter a value for 'YourControlNameOrYourDescription'.
Please make a valid entry or press ESC to Cancel"
'You could set the focus on the specific control if your wish, change
the background color, ...
End If
End Sub
I'm working on a legacy VB6 application. I'm sure this probably relates to VB.NET so i will tag it, but please let me know if it's completely different(which I dont think it is) then I'll remove the tag to avoid confusion.
Here is my issue....
I have a Tab control with multiple tabs: 0 - 3. On TabStuff.Tab = 0, I have a few textboxes and comboboxes. The user uses keyboard TAB to move from Indexed controls. What happens is once they get to the last control which is a textbox called txtCity - and click keyboard TAB once more, it brings them to TabStuff.Tab=1.
My issue is I do VALIDATE on txtCity - I call a function that verifies that a couple of the fields aren't NULL and if one of the fields is in fact NULL then I show a MSgBox and try to setFocus on that control. But instead, when OK is clicked on msgbox, it goes to the next tab which is TabStuff.tab=1 which is not correct.
Here's some of my code...
Dim FirstName, City as String
flag=false
firstName = txtName.text
city = txtcity.text
if FirstName="" or isnull(FirstName) then
msgbox "Please enter Name"
tabstuff.tab=0
txtname.setfocus
exit sub
elseif city = "" or isnull(city) then
msgbox "Please enter city"
tabstuff.tab=0
txtcity.setfocus
exit sub
end if
flag=true
This code is in txtCITY_VALIDATE
So in case city was empty, it shows MsgBox, stays on Tab=0 and setfocus on that control, but instead it goes to the next tab=1 and sets focus on the first control of that tab.
EDIT:
in txtCITY_LostFocus
If Flag = False Then
TabStuff.Tab = 0
Exit Sub
End If
I added this but it still goes to tabstuff.tab=1 setting the focus on first control of the tab
EDIT 2:
In a new project i created txt1 and txt2 - i set TabIndex 0 and 1 respectively.
Private Sub Txt1_Validate(Cancel As Boolean)
If Txt1.Text = "" Then
MsgBox "no text in txt1"
Txt1.SetFocus
End If
End Sub
This is the code I use. I click TAB on txt1 without entering any text, so this gets executed, but after msgbox, the focus gets set on txt2
For some extremely weird reason - i seem to have been getting this discrepancy because I was doign it in the VALIDATE property. When i entered the same code in LostFOCUS it seems to work fine. Thanks everyone for your help with this!
A checkbox controls whether a subform is visible. If the checkbox is "true," the subform is visible. The problem is, when I close and reopen the form the subform is no longer visible even though the checkbox is still true. I have to uncheck and re-check the checkbox before the subform becomes visible again. Here's what I'm using:
Private Sub RefBoardCkbx_Click()
If RefBoardCkbx.Value = True Then
[Admin Sep - Awaiting Prelim SubBox].Visible = True
Else
[Admin Sep - Awaiting Prelim SubBox].Visible = False
End If
End Sub
Obviously, there has to be some way for the form to automatically re-run the code everytime it opens--I don't know how to make it do that!
Use the main form's On Load event to make the subform visible when the form opens.
Me.[Admin Sep - Awaiting Prelim SubBox].Visible = True
You probably also want to put a check in the check box at the same time.
Me.RefBoardCkbx.Value = True
As a side point, consider whether this version of the click event procedure makes sense to you ...
Private Sub RefBoardCkbx_Click()
Me.[Admin Sep - Awaiting Prelim SubBox].Visible = Me.RefBoardCkbx.Value
End Sub
Is there anybody out here still programming VBA?
I'm trying to get this code to work
Private Sub button3_click()
'hide main buttons
button1.Visible = False
button2.Visible = False
button3.Visible = False
'show submenu buttons
button4.Visible = True;
button5.Visible = True;
End Sub
What I'm trying to do basically is that I have a main form that has 5 main button controls. 2 of them are hidden on startup. So when I click button 3, I want to hide the first 3 main buttons, and "unhide" the other two.
When trying to execute this event, I got an error
"Runtime Error 2165 - You can't hide a control that has the focus".
Has anybody come across this aspect of programming before? I'm sure it's doable. I just don't understand what went wrong here...
Change the focus to one of the visible control, before hiding the current one
Private Sub button3_click()
'show submenu buttons
button4.Visible = True
button5.Visible = True
DoEvents 'execute any pending events, to make sure the button 4 and 5 are really visible
button4.SetFocus 'change the focus to a now visible control
DoEvents 'execute any pending events, to make sure that button4 really has the focus
'now you can hide the other buttons
'hide main buttons
button1.Visible = False
button2.Visible = False
button3.Visible = False
End Sub
Maybe you can skip the DoEvents command, you should try
I would have thought that the error was explicit enough. Move the focus to some control that you are not trying to hide before you run your code. Also, consider Me : http://msdn.microsoft.com/en-us/library/aa223099(v=office.11).aspx