DLOOKUP question

G

Guest

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
 
S

strive4peace

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
*
 
G

Guest

try

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

Your last double quote was in the wrong plaxe
 
G

Guest

That's the ticket. Thanks.

Eric Blitzer said:
try

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

Your last double quote was in the wrong plaxe

Bonnie said:
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
 
G

Guest

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.

strive4peace said:
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,

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

Dlookup - yet another question 10
Dlookup Errors 3
DLookup questions 3
DlookUp Problems 1
DLookup with mulitple criteria - error message 5
Dlookup error 13 7
DLookup Problem 4
dlookup 2

Top