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

DLookup in TabControl in Form

I am trying to lookup phone numbers in a separate table based on the
name in the current Tab control

tblContacts has the fields: Name, Phone, Fax, and Email

In my Form's Tab control, I have the fields: DVP, Phone, Fax and
Email.
In the On Click properties of the Phone field, I have the following:

=DLookUp("[Phone]","[tblContacts]","[Name]='" & [DVP] & "'")

I am getting no results.

Any help would be greatly appreciated.
Thanks for your time.

Luane
Nov 13 '05 #1
6 3448
First, some bad news: 'Name' is a reserved Word in Access, and using it as
a field in a table is just asking for all sorts of wierd problems that will
cause you hours of frustration tracking down bugs because damn it the code
is right and why doesn't this work and why is my mdb crashing and ... etc.

So rename the field to something that is not in this list:

http://support.microsoft.com/kb/q286335/

Second, what is DVP? You say it is a field on your Tab Control, but you
don't mention it as a field of table tblContacts. Is it a field of that
table (I think not)? If not, then what is it? Cause if I don't know, does
your DCount statement know? Is it a textbox of the current form? If so,
then refer to it as Me.DVP.
Darryl Kerkeslager
"LSemos" <ls******@aol.com> wrote:
I am trying to lookup phone numbers in a separate table based on the
name in the current Tab control

tblContacts has the fields: Name, Phone, Fax, and Email

In my Form's Tab control, I have the fields: DVP, Phone, Fax and
Email.
In the On Click properties of the Phone field, I have the following:

=DLookUp("[Phone]","[tblContacts]","[Name]='" & [DVP] & "'")

I am getting no results.

Any help would be greatly appreciated.
Thanks for your time.

Luane

Nov 13 '05 #2
Thanks for the info on reserved words.
Have changed NAME to CONTACTNAME

DVP is an acronym for a position. It's value is the name of the DVP.
That name (i.e., Bob Smith) in the table is part of one record along
with ContactPhone, ContactFax and ContactEmail.

I agree that is probably where my problem lies; however, when I use
me.DVP I get the message
The object does not contain the Automation object 'me.' I also tried
[form name]![DVP]. Received the same result.

Occurred to me - does the field name in the table have to be the same
as the field name in the tab control. The Table field I want is
ContactPhone for a certain ContactName. In the form it is DVPPhone
for the person in field DVP.

Can we try this again? Any help?
Thanks
Luane

"Darryl Kerkeslager" <Ke*********@comcast.net> wrote in message news:<uL********************@comcast.com>...
First, some bad news: 'Name' is a reserved Word in Access, and using it as
a field in a table is just asking for all sorts of wierd problems that will
cause you hours of frustration tracking down bugs because damn it the code
is right and why doesn't this work and why is my mdb crashing and ... etc.

So rename the field to something that is not in this list:

http://support.microsoft.com/kb/q286335/

Second, what is DVP? You say it is a field on your Tab Control, but you
don't mention it as a field of table tblContacts. Is it a field of that
table (I think not)? If not, then what is it? Cause if I don't know, does
your DCount statement know? Is it a textbox of the current form? If so,
then refer to it as Me.DVP.
Darryl Kerkeslager
"LSemos" <ls******@aol.com> wrote:
I am trying to lookup phone numbers in a separate table based on the
name in the current Tab control

tblContacts has the fields: Name, Phone, Fax, and Email

In my Form's Tab control, I have the fields: DVP, Phone, Fax and
Email.
In the On Click properties of the Phone field, I have the following:

=DLookUp("[Phone]","[tblContacts]","[Name]='" & [DVP] & "'")

I am getting no results.

Any help would be greatly appreciated.
Thanks for your time.

Luane

Nov 13 '05 #3
When you say "field name in the tab control", you are actually referring to
a textBox, I presume. It will make things more clear if you and I both use
the proper names of the controls.

A textBox does not need to have the same name as the field in a table; in
fact, I would advise you to avoid that, becuase of the confusion. There are
'naming conventions' for all objects of any type in Access and VBA, and if
you Google 'naming conventions' I'm sure you'll find the details, but if you
at least stick with these basic ones, life will be a whole lot easier (and
of course, always avoid reserved words):

Controls, like textBoxes, comboBoxes, listBoxes, etc, should be prefixed
with a short (usually three-letter) code. Be as descriptive as needed:

Control - prefix - Example
-------------------------------
textBox - txt - txtEmployerName
combBox - cbo - cboEmployers
listBox - lst - lstEmployers

My preference for table names is to use the Oracle convention, which
basically says to write all table and field names in lower case, all SQL
words (SELECT, INSERT, AS, LIKE, ..) in uppercase, and all variables (which
would include conrtols)(Constants are all in CAPS) in mixed case like the
above controls. This makes reading SQL statements much easier. I name
tables with one descriptive, singular word:

employer
person
agency
address

Some people append 'tbl' to tables, which of course also works, like
tblContacts.

I then name the primary key as the table name plus the suffix _id:

employer_id

All other fields I prefix a short version of the table name with an
underscore

emp_name
emp_street
emp_city

Foreign keys are like so:

emp_per_id (a field in table employee that is the primary key from table
person)

Your naming scheme may vary, but *I would at least have one*, so that you
can be consistent. The bigger a project grows, the more you will appreciate
it. A good naming policy can also help you avoid overly long SQL, overly
confusing SQL, bad VBA, crashes, hard to track bugs, and premature baldness.

Okay, so now with DVP. You indicate that it is a field in the table, but
NOT a ontrol on the form. The keyword Me refers to the current form, so if
DVP was a textBox name, Me.DVP would be legit. But it's not.

I must admit that I am still somewhat confused by your suse of 'field'. In
a bound control, like a textBox, the data source, in other words, the field
of the table, is referred to as the controlsource (that's the property
name). So, if DVPPhone is a textBox on your form, and your form is in fact
a bound form (the recordsource is bound to a table), and bound to table
tblContacts, the the control source of Me.DVPPhone should be the
corresponding field in the table, perhaps tblContacts.DVP. So, if DVP is a
field in table tblContacts, my original advice to say Me.DVP would be wrong;
just use DVP as you did originally, and I assume that the bad field name,
'Name', was the cause of the original error..

Of course, you still have not explicitly said that DVP is a field of table
tblContacts, so that inference may be wrong.
Darryl Kerkeslager

"LSemos" <ls******@aol.com> wrote:
Thanks for the info on reserved words.
Have changed NAME to CONTACTNAME

DVP is an acronym for a position. It's value is the name of the DVP.
That name (i.e., Bob Smith) in the table is part of one record along
with ContactPhone, ContactFax and ContactEmail.

I agree that is probably where my problem lies; however, when I use
me.DVP I get the message
The object does not contain the Automation object 'me.' I also tried
[form name]![DVP]. Received the same result.

Occurred to me - does the field name in the table have to be the same
as the field name in the tab control. The Table field I want is
ContactPhone for a certain ContactName. In the form it is DVPPhone
for the person in field DVP.

"Darryl Kerkeslager" <Ke*********@comcast.net> wrote:
First, some bad news: 'Name' is a reserved Word in Access, and using it as a field in a table is just asking for all sorts of wierd problems that will cause you hours of frustration tracking down bugs because damn it the code is right and why doesn't this work and why is my mdb crashing and ... etc.
So rename the field to something that is not in this list:

http://support.microsoft.com/kb/q286335/

Second, what is DVP? You say it is a field on your Tab Control, but you
don't mention it as a field of table tblContacts. Is it a field of that
table (I think not)? If not, then what is it? Cause if I don't know, does your DCount statement know? Is it a textbox of the current form? If so, then refer to it as Me.DVP.
Darryl Kerkeslager
"LSemos" <ls******@aol.com> wrote:
I am trying to lookup phone numbers in a separate table based on the
name in the current Tab control

tblContacts has the fields: Name, Phone, Fax, and Email

In my Form's Tab control, I have the fields: DVP, Phone, Fax and
Email.
In the On Click properties of the Phone field, I have the following:

=DLookUp("[Phone]","[tblContacts]","[Name]='" & [DVP] & "'")

I am getting no results.

Any help would be greatly appreciated.
Thanks for your time.

Luane

Nov 13 '05 #4
First, thanks again for all the extra info. I thought I had a naming
convention, but you taught me how little I know. I appreciate your
putting me in the direction of learning more of the basics (i.e., the
language), because I do want a "good" database about which I can
communicate intelligently.

Now, let's see if I can describe this situation correctly:

In the tab control, txtDVP and txtDVPPhone are bound to the
controlsource tblBasicInfo.
In the txtDVPPhone OnClick properties, I want to get [ContactPhone]
from [tblContacts] where txtDVP is the same as
[tblContacts]![ContactName]

=DLookUp([ContactPhone],[tblContacts],[tblBasicInfo]![DVP]=[tblContacts]![ContactName])

Is being bound to a different table the problem?
Hope this is more clear. More of your time, please???
Thanks
Luane

"Darryl Kerkeslager" <Ke*********@comcast.net> wrote in message news:<Ir********************@comcast.com>...
When you say "field name in the tab control", you are actually referring to
a textBox, I presume. It will make things more clear if you and I both use
the proper names of the controls.

A textBox does not need to have the same name as the field in a table; in
fact, I would advise you to avoid that, becuase of the confusion. There are
'naming conventions' for all objects of any type in Access and VBA, and if
you Google 'naming conventions' I'm sure you'll find the details, but if you
at least stick with these basic ones, life will be a whole lot easier (and
of course, always avoid reserved words):

Controls, like textBoxes, comboBoxes, listBoxes, etc, should be prefixed
with a short (usually three-letter) code. Be as descriptive as needed:

Control - prefix - Example
-------------------------------
textBox - txt - txtEmployerName
combBox - cbo - cboEmployers
listBox - lst - lstEmployers

My preference for table names is to use the Oracle convention, which
basically says to write all table and field names in lower case, all SQL
words (SELECT, INSERT, AS, LIKE, ..) in uppercase, and all variables (which
would include conrtols)(Constants are all in CAPS) in mixed case like the
above controls. This makes reading SQL statements much easier. I name
tables with one descriptive, singular word:

employer
person
agency
address

Some people append 'tbl' to tables, which of course also works, like
tblContacts.

I then name the primary key as the table name plus the suffix _id:

employer_id

All other fields I prefix a short version of the table name with an
underscore

emp_name
emp_street
emp_city

Foreign keys are like so:

emp_per_id (a field in table employee that is the primary key from table
person)

Your naming scheme may vary, but *I would at least have one*, so that you
can be consistent. The bigger a project grows, the more you will appreciate
it. A good naming policy can also help you avoid overly long SQL, overly
confusing SQL, bad VBA, crashes, hard to track bugs, and premature baldness.

Okay, so now with DVP. You indicate that it is a field in the table, but
NOT a ontrol on the form. The keyword Me refers to the current form, so if
DVP was a textBox name, Me.DVP would be legit. But it's not.

I must admit that I am still somewhat confused by your suse of 'field'. In
a bound control, like a textBox, the data source, in other words, the field
of the table, is referred to as the controlsource (that's the property
name). So, if DVPPhone is a textBox on your form, and your form is in fact
a bound form (the recordsource is bound to a table), and bound to table
tblContacts, the the control source of Me.DVPPhone should be the
corresponding field in the table, perhaps tblContacts.DVP. So, if DVP is a
field in table tblContacts, my original advice to say Me.DVP would be wrong;
just use DVP as you did originally, and I assume that the bad field name,
'Name', was the cause of the original error..

Of course, you still have not explicitly said that DVP is a field of table
tblContacts, so that inference may be wrong.
Darryl Kerkeslager

"LSemos" <ls******@aol.com> wrote:
Thanks for the info on reserved words.
Have changed NAME to CONTACTNAME

DVP is an acronym for a position. It's value is the name of the DVP.
That name (i.e., Bob Smith) in the table is part of one record along
with ContactPhone, ContactFax and ContactEmail.

I agree that is probably where my problem lies; however, when I use
me.DVP I get the message
The object does not contain the Automation object 'me.' I also tried
[form name]![DVP]. Received the same result.

Occurred to me - does the field name in the table have to be the same
as the field name in the tab control. The Table field I want is
ContactPhone for a certain ContactName. In the form it is DVPPhone
for the person in field DVP.

"Darryl Kerkeslager" <Ke*********@comcast.net> wrote:
First, some bad news: 'Name' is a reserved Word in Access, and using it as a field in a table is just asking for all sorts of wierd problems that will cause you hours of frustration tracking down bugs because damn it the code is right and why doesn't this work and why is my mdb crashing and ... etc.
So rename the field to something that is not in this list:

http://support.microsoft.com/kb/q286335/

Second, what is DVP? You say it is a field on your Tab Control, but you
don't mention it as a field of table tblContacts. Is it a field of that
table (I think not)? If not, then what is it? Cause if I don't know, does your DCount statement know? Is it a textbox of the current form? If so, then refer to it as Me.DVP.
Darryl Kerkeslager
"LSemos" <ls******@aol.com> wrote:
> I am trying to lookup phone numbers in a separate table based on the
> name in the current Tab control
>
> tblContacts has the fields: Name, Phone, Fax, and Email
>
> In my Form's Tab control, I have the fields: DVP, Phone, Fax and
> Email.
> In the On Click properties of the Phone field, I have the following:
>
> =DLookUp("[Phone]","[tblContacts]","[Name]='" & [DVP] & "'")
>
> I am getting no results.
>
> Any help would be greatly appreciated.
> Thanks for your time.
>
> Luane

Nov 13 '05 #5
What you have here should work, except you need quotes around the
parameters, to indicate that you are using Strings (not variable names). I
have reversed the order of the final parameter, but I don't think that
should matter
=DLookUp("[ContactPhone]","[tblContacts]","[tblContacts]![ContactName]=[tblB
asicInfo]![DVP]")
Darryl Kerkeslager
"LSemos" <ls******@aol.com> wrote:
In the tab control, txtDVP and txtDVPPhone are bound to the
controlsource tblBasicInfo.
In the txtDVPPhone OnClick properties, I want to get [ContactPhone]
from [tblContacts] where txtDVP is the same as
[tblContacts]![ContactName]

=DLookUp([ContactPhone],[tblContacts],[tblBasicInfo]![DVP]=[tblContacts]![Co
ntactName])
Nov 13 '05 #6
Well, Darryl, thanks for all of your help. I give up. I just added a
subform to my tabcontrol. It isn't pretty, but at least I can move on.

Thanks again.
Luane

Darryl Kerkeslager wrote:
What you have here should work, except you need quotes around the
parameters, to indicate that you are using Strings (not variable names). I have reversed the order of the final parameter, but I don't think that should matter
=DLookUp("[ContactPhone]","[tblContacts]","[tblContacts]![ContactName]=[tblB asicInfo]![DVP]")
Darryl Kerkeslager
"LSemos" <ls******@aol.com> wrote:
In the tab control, txtDVP and txtDVPPhone are bound to the
controlsource tblBasicInfo.
In the txtDVPPhone OnClick properties, I want to get [ContactPhone]
from [tblContacts] where txtDVP is the same as
[tblContacts]![ContactName]

=DLookUp([ContactPhone],[tblContacts],[tblBasicInfo]![DVP]=[tblContacts]![Co ntactName])


Nov 13 '05 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: JLM | last post by:
What am I missing here? I have a form where I enter a "Class Code". This value corresponds to what sits in table "class code descriptions" along with the "title" of each "class code." Key...
6
by: Don Sealer | last post by:
I've written this expression for a DLookup function. It works almost alright. What I'm trying to do is type in a description and the ID field (number) populates automatically. It works almost as...
2
by: Francois Vanderseypen | last post by:
Can someone tell me why you cannot drag something onto a tabcontrol with zero tabpages? I have a kind of 'docking' interface and relies heavily on GDI+, a screenshot is available here: ...
8
by: Aaron Ackerman | last post by:
If I am expanding (maximizing a form how do I maximize the tab control along with it?
9
by: Michael Turner | last post by:
Hi Guys Having problem with the tab control, I need to set the background color to something different than the standard, I have found code on the web and now can redraw the tabpage buttons so...
2
by: Simon Verona | last post by:
I have a few hundred forms in my application. All are based on a custom base form class. I decided that I wanted to globally change the look and feel of many of the controls in my application -...
5
by: hrreece | last post by:
I have a form, Master List Temp, in Access 2003 that uses the Dlookup command to pull values from another table, Address Master. The user types in a person's home phone number in the HomePhone field...
0
by: bertie78 | last post by:
Hi all, New poster here! I'm having some difficulty updating a tabcontrol cross-threads. The general idea is : the main thread is the owner of the tab control and the form controls. However, due...
2
by: Jamey | last post by:
Ran into an inconvenience with TabControls yesterday. I found a partial explanation from Allen Browne on the MS message boards explaining when it happens, but not why. I thought Stephen Lebans...
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: 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
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,...

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.