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
6 1773
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: -
If textbox1.text = "" then
-
Report_sub.visible = false
-
else
-
Report_sub.visible = true
-
end if
-
In comparison, a combobox would look something like this: -
if combobox1.SelectedValue = "" then
-
Report_sub.visible = false
-
else
-
Report_sub.visible = true
-
end if
-
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
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: -
If textbox1.text = "" then
-
Report_sub.visible = false
-
else
-
Report_sub.visible = true
-
end if
-
In comparison, a combobox would look something like this: -
if combobox1.SelectedValue = "" then
-
Report_sub.visible = false
-
else
-
Report_sub.visible = true
-
end if
-
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
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
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.
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: -
if textbox1 = "" then
-
Report_sub.setfocus
-
Report_sub.visible = false
-
end if
-
It's getting erased because of the OnCurrent Event. When you scroll, it's activating the Event.
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: -
Employee_First_Name.SetFocus
-
If Employee_First_Name.Text = "" Then
-
Me.Report_Sub.Visible = False
-
ElseIf Employee_First_Name.Text <> "" Then
-
Employee_Last_Name.SetFocus
-
If Employee_Last_Name.Text = "" Then
-
Me.Report_Sub.Visible = False
-
ElseIf Employee_Last_Name.Text <> "" Then
-
Extension.SetFocus
-
If Extension.Text = "" Then
-
Me.Report_Sub.Visible = False
-
ElseIf Extension.Text <> "" Then
-
Group_Box.SetFocus
-
If Group_Box.SelText = "" Then
-
Me.Report_Sub.Visible = False
-
ElseIf Group_Box.SelText <> "" Then
-
Me.Report_Sub.Visible = True
-
End If
-
End If
-
End If
-
End If
-
Thanks again for the advice, you guys are awesome.
Sign in to post your reply or Sign up for a free account.
Similar topics
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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
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 =...
|
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,...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
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: 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: 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,...
|
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,...
|
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...
| |