473,386 Members | 1,720 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

on current event only working going forward

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:
Attached Files
File Type: docx visibility code.docx (13.0 KB, 270 views)
Jan 15 '13 #1

✓ answered by Seth Schrock

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
Rabbit
12,516 Expert Mod 8TB
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.
Jan 15 '13 #2
yes, it is an access question. sorry
Jan 15 '13 #3
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 :
  1. Sets the visibility to True when it should be visible.
  2. 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.
Jan 15 '13 #4
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?
Jan 15 '13 #5
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.

Expand|Select|Wrap|Line Numbers
  1. Private Sub Mylist_AfterUpdate()
  2.       Dim i As Long
  3.       For i = 0 To MyList.ListCount - 1
  4.           If MyList.Selected(0) Then
  5.             txtOfcHW.Enabled = True
  6.           Else
  7.             txtOfcHW.Enabled = False
  8.  
  9.           If MyList.Selected(1) Then
  10.             txtOfcSW.Enabled = True
  11.           Else
  12.             txtOfcSW.Enabled = False
  13.           End If
  14.           End If
  15.       Next i
  16.  
  17. 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.

Expand|Select|Wrap|Line Numbers
  1. Private Sub Form_Current()
  2.   If txtOfcHW <> "" Then
  3.    txtOfcHW.Enabled = True
  4.   Else
  5.    txtOfcHW.Enabled = False
  6.  
  7.   If txtOfcSW <> "" Then
  8.    txtOfcSW.Enabled = True
  9.   Else
  10.    txtOfcSW.Enabled = False
  11. End If
  12. End If
  13. 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.
Jan 15 '13 #6
Rabbit
12,516 Expert Mod 8TB
Are you sure it's a blank string and not a null? They sometimes look the same but are not.
Jan 15 '13 #7
I changed it to read:

Expand|Select|Wrap|Line Numbers
  1. Private Sub Form_Current()
  2.     If Not IsNull([txtOfcHW]) Then
  3.             txtOfcHW.Enabled = True
  4.         Else
  5.             txtOfcHW.Enabled = False
  6.             If Not IsNull([txtOfcSW]) Then
  7.                     txtOfcSW.Enabled = True
  8.                 Else
  9.                     txtOfcSW.Enabled = False
  10.             End If
  11.     End If
  12. 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.
Jan 15 '13 #8
Rabbit
12,516 Expert Mod 8TB
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.
Jan 15 '13 #9
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 :
Expand|Select|Wrap|Line Numbers
  1. Private Sub Form_Current()
  2.   With Me.txtOfcHW
  3.     .Enabled = (.Value > "")
  4.   End With
  5.   With Me.txtOfcSW
  6.     .Enabled = (.Value > "")
  7.   End With
  8. End Sub
PS. Checking a control's value is <> "" or even > "" works for Null results as well as ZLS ("") ones.
Jan 15 '13 #10
I'm not sure I understand how it would be written if they aren't supposed to be separate If statements.
Jan 15 '13 #11
Seth Schrock
2,965 Expert 2GB
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.
Jan 16 '13 #12
Thanks Seth, works perfectly. On to the next question.
Jan 16 '13 #13
Seth Schrock
2,965 Expert 2GB
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.
Jan 16 '13 #14
Thanks, will do. sorry, learning my way around this site. Lots of great help. thanks again.
Jan 16 '13 #15
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.
Jan 16 '13 #16
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.
Jan 17 '13 #17
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.
Jan 17 '13 #18

Sign in to post your reply or Sign up for a free account.

Similar topics

1
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...
2
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...
19
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...
3
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 ?
3
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
1
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...
1
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...
0
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....
7
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...
1
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...
0
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$) { } ...
0
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...
0
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...
0
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
0
BarryA
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...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
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...
0
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...
0
jinu1996
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...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.