Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion GroupsFormsForms ProgrammingQueriesModules / DAO / VBAReports / PrintingMacrosDatabase DesignSecurityConversionImporting / LinkingSQL Server / ADPMultiuser / NetworkingReplicationSetup / ConfigurationDeveloper ToolkitsActiveX ControlsNew UsersGeneral 1General 2
Access DirectoryToolsTutorialsUser Groups
Related Topics
SQL ServerOther DB ProductsMS OfficeMore Topics ...

MS Access Forum / General 2 / February 2007

Tip: Looking for answers? Try searching our database.

DLOOKUP question

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Bonnie - 22 Feb 2007 23:29 GMT
Hi,

I am trying to populate a field on a form with the following line of code:

Me.LASTNAME.Value = DLookup("[LNAME]", "[TEST]", "[SLNUM] = " & MSL)

I get the error:  Runtime error 2001  You canceled the previous operation.

Any ideas?  

Thanks in advance.

Bonnie
strive4peace - 23 Feb 2007 01:05 GMT
Combobox Example
---

Hi Bonnie,

Is MSL a control NAME on your form?

Rather than using a dLookup, why not make SLNum a combo with LNAME as
one of the columns -- then you can use a calculated field to show it
(you should not store it in 2 places).  Here is an analogy:

Combobox Example

Store names in just one place.  For instance, if you have a People
table, define a PID (or PeopleID) autonumber field.  You will also have
fields for Firstname, Lastname, etc.  Then, in other tables, when you
want to identify a person, you can use the key field.  One way to do this…

Create an autonumber field in the People table -->

PID, autonumber

then, in the other tables...
PID, long, DefaultValue = Null

Then, when you want to put data in (which should be done from a form),
you can set it up to pick names from a list but store the PID.

~~~~~

from the design view of a form, add a combobox control and give it a
logical name

Name --> PID

ControlSource --> PID

RowSource -->
 SELECT
    PID,
    LastName & ", " & Firstname AS Fullname,
    BirthDate
 FROM People
 ORDER BY LastName, Firstname
(you can click in the RowSource property, click on the Builder Button
(...) to the right and use a tool that works like the one you are
probably familar with for queries if SQL is not your strong suit)

BoundColumn --> 1

ColumnCount --> 3

columnWidths --> 0;2;1
    (etc for however many columns you have -- the ID column will be hidden)

ListWidth --> 3
    (should add up to the sum of the column widths)

if you have a listbox, sometimes you need to make the width .01 more
than the sum of the columns to prevent the horizontal scrollbar from
appearing.

PID will be stored in the form RecordSource while showing you names from
another table... a MUCH better and more reliable method.

If you want to show other information from your combobox in other
controls, you can use calculated fields.  For instance

textbox:
Name --> BirthDate
ControlSource --> = PID.column(2)

The reason that column 2 is referenced instead of column 3 is that
column indexes start with 0, not 1, in Access.

~~~~

if you would like to learn more about properties and SQL, email me and
request my 30-page Access Basics document -- be sure to put "Access
Basics" in the subject or I may miss your message

Warm Regards,
Crystal
 *
     (:  have an awesome day  :)
  *
MVP Access
Remote Programming and Training
strive4peace2006 at yahoo.com
  *

> Hi,
>
[quoted text clipped - 9 lines]
>
> Bonnie
Bonnie - 23 Feb 2007 04:11 GMT
The DLOOKUP is a better solution for this particular application because I
don't just want to offer and grab existing SLNUM's  but want to have my girls
do regular data entry and populate some fields with last months data from
them to review and possibly change.  I do use and enjoy comboboxes in other
circumstances though.

Thanks for taking the time though.

> Combobox Example
> ---
[quoted text clipped - 100 lines]
> >
> > Bonnie
Eric Blitzer - 23 Feb 2007 01:38 GMT
try

Me.LASTNAME.Value = DLookup("[LNAME]", "[TEST]", "[SLNUM] =  & MSL")

Your last double quote was in the wrong plaxe

> Hi,
>
[quoted text clipped - 9 lines]
>
> Bonnie
Bonnie - 23 Feb 2007 04:08 GMT
That's the ticket.  Thanks.

> try
>
[quoted text clipped - 15 lines]
> >
> > Bonnie
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.