473,385 Members | 1,780 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,385 software developers and data experts.

Hiding a form: If conditions

I'm a beginner programmer so bear with me if this seems very simple...

I have a subform which I don't want to have displayed until the user has entered first name, last name, extension, and chose a dept. from a combobox.

The If condition I tried for the first name was:

If Me.Employee_First_Name.Value = Null Then
Me.Report_Sub.Visible = False
Else
Me.Report_Sub.Visible = True
End If

But this does not hide the subform, it seems to do nothing. I also tried "" instead of Null but to no avail. If I try "Me.Employee_First_Name.Text" instead of .Value I get the error:

"You can't reference a property or method for a control unless the control has the focus."

I plan on adding in the conditions for last name, extension, and dept. eventually but can't get this first condition to work. The 'extension' is obviously set as a number so is default 0, so I have gotten this condition to work because I can get it to equal the default value of a new record:

If Me.Extension.Value = 0 Then

But the other 3 are killing me. I just want the subform hidden if all fields are null or empty. I also am not sure if the combobox for dept. should be set as .value as well or something different because it's a combobox. Please help me out! Thanks in advance.


- Adam
Jan 16 '08 #1
6 1773
MindBender77
234 100+
I'm a beginner programmer so bear with me if this seems very simple...

I have a subform which I don't want to have displayed until the user has entered first name, last name, extension, and chose a dept. from a combobox.

The If condition I tried for the first name was:

If Me.Employee_First_Name.Value = Null Then
Me.Report_Sub.Visible = False
Else
Me.Report_Sub.Visible = True
End If

But this does not hide the subform, it seems to do nothing. I also tried "" instead of Null but to no avail. If I try "Me.Employee_First_Name.Text" instead of .Value I get the error:
- Adam
Assuming your using a textbox for firstname, lastname and extension.
You could try something like this:

Expand|Select|Wrap|Line Numbers
  1. If textbox1.text = "" then
  2. Report_sub.visible = false
  3. else
  4. Report_sub.visible = true
  5. end if
  6.  
In comparison, a combobox would look something like this:
Expand|Select|Wrap|Line Numbers
  1. if combobox1.SelectedValue = "" then
  2. Report_sub.visible = false
  3. else
  4. Report_sub.visible = true
  5. end if
  6.  
Tip: I would put all of the criteria into the same if statement to make the code easier for you to read.

Hope this helps,
JS
Jan 16 '08 #2
I tried this code, and still got the same error as before:

"You can't reference a property or method for a control unless the control has the focus."

I have no idea what this means. Also, I am using Access 2000 and I assume an older version of VB as well because there is no 'SelectedValue' for my combobox, only 'SelLength' 'SelStart' and 'SelText'. I obviously used 'SelText' and get the same error as I did with the textboxes.

Side note: I am placing all of this code on the form itself under the Event "On Current." Is this correct?

Thanks for the reply, any other ideas?




Assuming your using a textbox for firstname, lastname and extension.
You could try something like this:

Expand|Select|Wrap|Line Numbers
  1. If textbox1.text = "" then
  2. Report_sub.visible = false
  3. else
  4. Report_sub.visible = true
  5. end if
  6.  
In comparison, a combobox would look something like this:
Expand|Select|Wrap|Line Numbers
  1. if combobox1.SelectedValue = "" then
  2. Report_sub.visible = false
  3. else
  4. Report_sub.visible = true
  5. end if
  6.  
Tip: I would put all of the criteria into the same if statement to make the code easier for you to read.

Hope this helps,
JS
Jan 16 '08 #3
kadghar
1,295 Expert 1GB
I tried this code, and still got the same error as before:

"You can't reference a property or method for a control unless the control has the focus."


Thanks for the reply, any other ideas?
you have to focus it before you can change its properties.

use SHOW or SETFOCUS depending if it's already shown and of the version of VB and after that, you can change its properties, such as visible.

HTH
Jan 16 '08 #4
Ok now it's getting more interesting...

I added the setfocus control, and have the following code:

Employee_Last_Name.SetFocus
If Employee_Last_Name.Text = "" Then
Me.Report_Sub.Visible = False
Else: Employee_Last_Name.Text = ""
Me.Report_Sub.Visible = True
End If


For some reason, when i scroll through my records, anywhere that there once was a last name, it gets erased. When i scroll to the next record, i can see the last name there for a split second then it disappears and is erased. I don't know why this code would have caused that. Any ideas??

The last name is set as a required field in its table settings if that has any effect on this.
Jan 16 '08 #5
MindBender77
234 100+
I tried this code, and still got the same error as before:

"You can't reference a property or method for a control unless the control has the focus."

I have no idea what this means. Also, I am using Access 2000
I was unaware you were using Access VBA. It's slightly different than regular VB and I agree that focus has to be set to modify.

Try something like this in your OnCurrent Event:
Expand|Select|Wrap|Line Numbers
  1. if textbox1 = "" then
  2. Report_sub.setfocus
  3. Report_sub.visible = false
  4. end if
  5.  
It's getting erased because of the OnCurrent Event. When you scroll, it's activating the Event.
Jan 16 '08 #6
Thanks for all of the help guys, input from both of you helped me solve the problem. To get it all to work, and in the same condition it ended up looking like this, in case somebody in the future has the same problem:

Expand|Select|Wrap|Line Numbers
  1. Employee_First_Name.SetFocus
  2.     If Employee_First_Name.Text = "" Then
  3.         Me.Report_Sub.Visible = False
  4.     ElseIf Employee_First_Name.Text <> "" Then
  5.         Employee_Last_Name.SetFocus
  6.         If Employee_Last_Name.Text = "" Then
  7.             Me.Report_Sub.Visible = False
  8.         ElseIf Employee_Last_Name.Text <> "" Then
  9.             Extension.SetFocus
  10.             If Extension.Text = "" Then
  11.                 Me.Report_Sub.Visible = False
  12.             ElseIf Extension.Text <> "" Then
  13.                 Group_Box.SetFocus
  14.                 If Group_Box.SelText = "" Then
  15.                     Me.Report_Sub.Visible = False
  16.                 ElseIf Group_Box.SelText <> "" Then
  17.                     Me.Report_Sub.Visible = True
  18.                 End If
  19.             End If
  20.         End If
  21.     End If
  22.  
Thanks again for the advice, you guys are awesome.
Jan 16 '08 #7

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

Similar topics

4
by: James Greig | last post by:
hello people, i'm just learning javascript, could someone point me in the direction of an example of the following, or give me some clues as to how it might be done: what i would like to do...
10
by: Gregory A Greenman | last post by:
I'm trying to write a program in vb.net to automate filling out a series of forms on a website. There are three forms I need to fill out in sequence. The first one is urlencoded. My program is...
4
by: middletree | last post by:
I had this going yesterday, but it seems to be forgotten because it's so far down the list now. www.middletree.net/dropdown.htm This is from an Intranet app I have going in ASP. I have no...
2
by: George Steward | last post by:
I have a form in which I only want certain boxes to show under certain conditions, for example, when a transaction is selected as "commission" I need to show the fields for entering the relevant...
1
by: Bogdan Zamfir | last post by:
Hi, I have a web page with two frames. Left one has a aspk page with application menu, and right one has the astive working form Depending on some conditions in right page, I want to be able...
0
by: Michelle Stone | last post by:
I have several Data Adapters, and depending on certain conditions, I set one of them as the DataSource for a datagrid on my web form. In each of the data adapters, I have the primary key of the...
1
by: Doug | last post by:
Looking for opinions/suggestions: Suppose I have a "region" of an aspx page I want to hide or show based on whatever runtime conditions. Additionally, the entire region is defined by an HTML...
11
by: Alex | last post by:
Hello all, I have a main form(say "form1") .i want to display another form(say "form2") on occuring of an event (say a button click) and want to hide it after some time so that it will again...
3
by: paulus4605 | last post by:
dears since I'm new to ruby I try to create a form within ruby on rails. this is my controller require "player" class SpelersController < ApplicationController def index @speler =...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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: 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...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
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.