PC Review


Reply
Thread Tools Rate Thread

How do I read a value from table and store to variable using VBA

 
 
Aldo
Guest
Posts: n/a
 
      13th Jun 2009
Hi guys,
How do I read a value from a table and store it in a variable using VBA?
I need to read the value using
SELECT Sex.SexID FROM Sex WHERE Sex.SexDes = "male"
Thanks in advance for any help,
Aldo.
 
Reply With Quote
 
 
 
 
John W. Vinson
Guest
Posts: n/a
 
      13th Jun 2009
On Sat, 13 Jun 2009 10:27:01 -0700, Aldo <(E-Mail Removed)>
wrote:

>Hi guys,
>How do I read a value from a table and store it in a variable using VBA?
>I need to read the value using
>SELECT Sex.SexID FROM Sex WHERE Sex.SexDes = "male"
>Thanks in advance for any help,
>Aldo.


intSex = DLookUp("[SexID]", "[Sex]", "[SexDes] = 'male'")

This take the place of your query. You could open the query and use a
Recordset but that would involve several additional lines of code.
--

John W. Vinson [MVP]
 
Reply With Quote
 
Aldo
Guest
Posts: n/a
 
      14th Jun 2009
Hi John, Thanks for answering.
I am trying intSex = DLookup("[SexID]", "[Sex]", "[SexDes] = 'Male'")
, but getting Error 94 "Invalid use of null"
Thanks,
Aldo.


"John W. Vinson" wrote:

> On Sat, 13 Jun 2009 10:27:01 -0700, Aldo <(E-Mail Removed)>
> wrote:
>
> >Hi guys,
> >How do I read a value from a table and store it in a variable using VBA?
> >I need to read the value using
> >SELECT Sex.SexID FROM Sex WHERE Sex.SexDes = "male"
> >Thanks in advance for any help,
> >Aldo.

>
> intSex = DLookUp("[SexID]", "[Sex]", "[SexDes] = 'male'")
>
> This take the place of your query. You could open the query and use a
> Recordset but that would involve several additional lines of code.
> --
>
> John W. Vinson [MVP]
>

 
Reply With Quote
 
Aldo
Guest
Posts: n/a
 
      14th Jun 2009
I used Nz() to manage null values.
Thanks for your help!
Aldo.




"John W. Vinson" wrote:

> On Sat, 13 Jun 2009 10:27:01 -0700, Aldo <(E-Mail Removed)>
> wrote:
>
> >Hi guys,
> >How do I read a value from a table and store it in a variable using VBA?
> >I need to read the value using
> >SELECT Sex.SexID FROM Sex WHERE Sex.SexDes = "male"
> >Thanks in advance for any help,
> >Aldo.

>
> intSex = DLookUp("[SexID]", "[Sex]", "[SexDes] = 'male'")
>
> This take the place of your query. You could open the query and use a
> Recordset but that would involve several additional lines of code.
> --
>
> John W. Vinson [MVP]
>

 
Reply With Quote
 
John W. Vinson
Guest
Posts: n/a
 
      14th Jun 2009
On Sat, 13 Jun 2009 22:29:01 -0700, Aldo <(E-Mail Removed)>
wrote:

>Hi John, Thanks for answering.
>I am trying intSex = DLookup("[SexID]", "[Sex]", "[SexDes] = 'Male'")
>, but getting Error 94 "Invalid use of null"
>Thanks,
>Aldo.


An Int datatype cannot accept a NULL, so if there are no Male records in [Sex]
(radical feminist databases!? Who knew?) you'll get this error, since DLookUp
will return NULL. If you Dim intSex as a Variant you can avoid this error.
--

John W. Vinson [MVP]
 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
How to read a user input value from command line and store it in a variable? Tony Bansten Microsoft VB .NET 0 25th Mar 2009 08:52 AM
Store a variable =?Utf-8?B?YWNvcmVz?= Microsoft Access Forms 1 1st Oct 2006 04:02 PM
Read file attributes and store in a table ???????? DavPet Microsoft Access Getting Started 3 8th Jan 2006 11:46 AM
SQL Server Store Procedure returning data from a temp table or a table variable to Access anasser Microsoft Access 1 21st Oct 2005 03:55 PM
best way to store very variable length string in sql table Steve Richter Microsoft ADO .NET 3 4th Jun 2005 08:41 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 11:15 PM.