I have textboxes that become enabled based on a listbox so users can enter data. However, I'd like them to stay not enabled if no text is inputted. The code I have in the "current" even, makse this happen but only when I move forward through the records. If I move back, the textboxes enabled from other records remain enabled, even if there is no text in them.
Ex. rec 1 has data in txtbox 1
rec 2 has data in txtbox 3
When you move from rec 1 to rec 2 txtbox 1 becomes no enabled since there is no data in it. All good, but when I go from rec 2 to rec 1, txtbox 3 remains enabled when it should be not enabled since there is no text in that box for rec 1.
See attached code:
They should be separate IF statements, but the way that you have your code, the second IF statement is inside of the first. So you would need to add an End If in line 8 of the first block of code and line 6 of the second block and then remove the End If in line 14 of the first block and line 12 of the second block to make them separate IF statements.
17 1762
As a rule of thumb, I do not download attachments from strangers. Please post the code in the thread instead. Surround the code in code tags when doing so.
This sounds like an Access question, if so, you are in the wrong forum. Let me know and I'll move it to the Access forum.
yes, it is an access question. sorry
NeoPa 32,556
Expert Mod 16PB Rabbit:
Please post the code in the thread instead. Surround the code in code tags when doing so.
@SeadooRider.
Please pay attention to what's posted - especially when posted by a moderator (They have "Mod" in green below any avatar over on the left). To help you we need to see your code.
As for your question, you need to ensure the code that is run does both of : - Sets the visibility to True when it should be visible.
- Sets the visibility to False when it should not be visible.
Otherwise you'll see exactly what you report. Once any record sets the visibility to True it will stay True for ever.
NeoPa 32,556
Expert Mod 16PB Rabbit:
Please post the code in the thread instead. Surround the code in code tags when doing so.
@SeadooRider. Please pay attention to what's posted - especially when posted by a moderator (They have "Mod" in green below any avatar over on the left). To help you we need to see your code.
Does anyone else ever get that feeling of déja vu?
Ok, so I have a listbox with OfcHW and OfcSW among others in it.
With the code below, as I click an item, the corresponding txtbox becomes enabled. - Private Sub Mylist_AfterUpdate()
-
Dim i As Long
-
For i = 0 To MyList.ListCount - 1
-
If MyList.Selected(0) Then
-
txtOfcHW.Enabled = True
-
Else
-
txtOfcHW.Enabled = False
-
-
If MyList.Selected(1) Then
-
txtOfcSW.Enabled = True
-
Else
-
txtOfcSW.Enabled = False
-
End If
-
End If
-
Next i
-
-
End Sub
And on current, I have the following code which should check to see if the txtboxes have data. If not they are not supposed to be enabled. - Private Sub Form_Current()
-
If txtOfcHW <> "" Then
-
txtOfcHW.Enabled = True
-
Else
-
txtOfcHW.Enabled = False
-
-
If txtOfcSW <> "" Then
-
txtOfcSW.Enabled = True
-
Else
-
txtOfcSW.Enabled = False
-
End If
-
End If
-
End Sub
However, it seems to be remembering what was selected for the 2nd record because the 2nd txtbox remains enabled when returning to the 1st record even when there is no txt in the box in the 1st record.
I'm sure that is clear as mud but I'm sure it has an easy fix I'm just not putting together or I'm conflicting what I want to form to do.
Thx.
Are you sure it's a blank string and not a null? They sometimes look the same but are not.
I changed it to read: - Private Sub Form_Current()
-
If Not IsNull([txtOfcHW]) Then
-
txtOfcHW.Enabled = True
-
Else
-
txtOfcHW.Enabled = False
-
If Not IsNull([txtOfcSW]) Then
-
txtOfcSW.Enabled = True
-
Else
-
txtOfcSW.Enabled = False
-
End If
-
End If
-
End Sub
and it does the same thing. seems to disable fields without text in them if I'm advancing, but not when I'm going to previous records.
I also tried putting this code into the next and previous command buttons with no success there either.
Please use code tags when posting code.
That is odd, you may have to zip and attach the database so we can examine it closer.
NeoPa 32,556
Expert Mod 16PB
Even though your code is not indented to indicate it, your second If statement (Line #7 from post #8) is included within the first (which is why it will not work reliably when going backwards, but only in certain restricted circumstances).
Try instead : - Private Sub Form_Current()
-
With Me.txtOfcHW
-
.Enabled = (.Value > "")
-
End With
-
With Me.txtOfcSW
-
.Enabled = (.Value > "")
-
End With
-
End Sub
PS. Checking a control's value is <> "" or even > "" works for Null results as well as ZLS ("") ones.
I'm not sure I understand how it would be written if they aren't supposed to be separate If statements.
They should be separate IF statements, but the way that you have your code, the second IF statement is inside of the first. So you would need to add an End If in line 8 of the first block of code and line 6 of the second block and then remove the End If in line 14 of the first block and line 12 of the second block to make them separate IF statements.
Thanks Seth, works perfectly. On to the next question.
As that is a different question than was originally asked, it must be asked in a different thread. Also, when you do repost it, please use code tags. The button just above where you type that says <CODE/> adds the code tags for you. It is incredibly hard to read code that doesn't have these included to format it.
Thanks, will do. sorry, learning my way around this site. Lots of great help. thanks again.
NeoPa 32,556
Expert Mod 16PB SeadooRider:
I'm not sure I understand how it would be written if they aren't supposed to be separate If statements.
Seth's answered that question, but frustratingly you make no comment on the suggested code. Is it what you're referring to when you say "Thanks Seth, works perfectly."? Or maybe you just ignored it completely. Your posts don't make that clear.
Well, let me be a little more clear. The answer Seth provided made perfect sense. I put my End If after each IF statement and my form responded as I originally hoped it would. He provided the explaination I needed to make the correct changes to my code. I furthermore sincerely appreciate his assistance in the matter and hope I wasn't to much of a burden with my question. In addition, I didn't ignore anyone, I thanked him for his help and indicated that his answer solved my problem.
I'll try to be a little more clear in my responses from now on Mr NepPa.
NeoPa 32,556
Expert Mod 16PB SeadooRider:
I'll try to be a little more clear in my responses from now on Mr NepPa.
Please do.
As for responding to all, I see no comment that sensibly responds to post #10. I wasn't sure whether or not post #13 alluded to it in any way, but if you say that was referring to Seth's instructions in post #12, rather than my post then I'm really unclear why you claim nobody was ignored, particularly as it provided an answer to the question you asked even before you posted the question. Perhaps it wasn't any attempt to ignore, but you didn't see it? That happens sometimes, but you can probably understand why I'm still a little confused by your answers and the flow of the thread.
Sign in to post your reply or Sign up for a free account.
Similar topics
by: matthewemiclea |
last post by:
I have a subform, where in the "on current" event, I display code that
is supposed to recognize which record I am pointing to, and then
display more specific info in another subform based on that...
|
by: sasan3 |
last post by:
on "AFTER UPDATE" event of a GROUP OPTION on a form, I requery its
subform. The "CURRENT" event of subform however happens 3 times (as
detected when I stop in ON_CURRENT method of subform).
What...
|
by: Christopher W. Douglas |
last post by:
I am writing a VB.NET application in Visual Studio 2003. I have written a
method that handles several events, such as closing a form and changing the
visible status of a form. I have some code...
|
by: Rob |
last post by:
Let's say the event is form Load....
Is there code you could use within that Sub that would return that the
current event is Load ?
i.e.,
Me.CurrentEvent
or something like that ?
|
by: doctorle |
last post by:
I'm surprised that the Current event of forms always fires twice
(Access XP).
I have quite a lot of processing done in the current event, how to make
the code run just once?
Thanks
|
by: Diana |
last post by:
I've got a database that has been working successfully for a number of
years now. I just added a new item - basically a field that becomes
visible depending on another field's value. When I was...
|
by: prasadsurya |
last post by:
My requirement is, i need to capture an event when user closing browser i need to open a pop up window. I got the code which is working fine. But when i go forward and came back to the previous page...
|
by: jamcompany via AccessMonster.com |
last post by:
I have set up speed testing. I noticed that the majority of the time to load
the login form (the form listed in my startup) is between the Form's Current
event and the first control's Enter event....
|
by: Neil |
last post by:
I have some code in my form's On Current event which changes focus to a
particular control. I want the control to remain where it was when the user
moved to the new record. But using...
|
by: Cornishgamehen |
last post by:
Hi,
I seem to have discovered a bug/problematic feature in Access 2002.
When navigating through records in a form, if a control in one of the subforms has the focus, and that subform becomes...
|
by: aa123db |
last post by:
Variable and constants
Use var or let for variables and const fror constants.
Var foo ='bar';
Let foo ='bar';const baz ='bar';
Functions
function $name$ ($parameters$) {
}
...
|
by: ryjfgjl |
last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
| |