Get Data from DBtable using code

  • Thread starter Thread starter Simon Davis
  • Start date Start date
S

Simon Davis

Access 2K , Win XPpro , Novice Coder

I want to be able to access data from a table in my DB
using code and show it on a form as follows :

Table Structure

Name : Text
RefNo ( Primary Key ) : Number

On the form I want to type in a name (contained within the
table ) in a textbox and the RefNo to be displayed in
another text box.

Can this be done and is there any code available to
achieve this.

Thanks in advance for any assistance

Simon.
 
A few things.

(1) "Name" is not good as the name of a table field. It is a so-called
"reserved word" in Acess. Check out "reserved words" in Access Help. If you
must use it, you'll need to enclose it in square brackets in various
contexts (ie. [Name]).

(2) If Name is not the primary key, and you do not have a unique index on
it, there could in theory be many identical names (each with a different
refno). So when you say that you want to enter a name & display the refno,
there might be >many< refno's one for each record with a matching name. If
you want to prevent that, & ensure that no two records have identical names,
put a unique index on the Name field. Otherise, you'll have to display the
matching refnos in a drop-down list, for example - not a simple textbox.

(3) Check out the AfterUpdate event, and the DLookup function, in online
help. You need for the AfterUpdate event of the checkbx, to use the
DLookup() function, to find the (first or only) refno for the name that the
user enters in the textbox.

HTH,
TC
 
TC said:
(3) Check out the AfterUpdate event, and the DLookup function, in online
help. You need for the AfterUpdate event of the checkbx, to use the

.... AfterUpdate event of the *TEXT*box ...

TC
 
Back
Top