Re: Simplest way to run 2 queries invoked by a form?



On Wed, 17 Aug 2005 08:32:08 +0100, Jeremy
<newspostings@xxxxxxxxxxxxxx> wrote:

>Here's the requirement.
>
>User needs to be able to enter 2 items of data onto a form and press a
>button. The code behind the button needs to check that both fields have
>a valid entry (one is a pick list of values 1-3 the other is a date) and
>then execute 2 SQL statements.
>
>1) do i put the sql statements into individual queries?

That depends. What do the two queries DO? Are they update queries
updating an existing record in a table? Same table? different tables?
Or Append queries adding a new record (or records)?

>2) presuming I use the "on click" method on the button, how would I code
>references to the two fields on the orm?

Me!Controlname

>3) within the sql, how do I refer to values of the two fields on the
>form?

Again... Me!ControlName. If you're building the SQL string just
concatenate that reference.

>This is part of a voluntary project - not my area of expertise at all,
>so appreciate some simple code examples or pointers to where I can get a
>primer in how to do this elementary stuff with Access.

This isn't elementary. Using unbound controls and code to update
tables is fairly advanced, and is USUALLY not necessary! Typically
you'ld simply bind the controls to fields in a table to update them.

If the first field is a pick list (a "Combo Box" in Access jargon) you
can set its Limit to List property to True, and the user won't be ABLE
to select an invalid entry, presuming that the combo's row source
contains only valid entries. The date field could have a date Input
Mask, and you could use its BeforeUpdate event to check for a valid
date range.

Do you have some particular reason for wanting to do it the hard way?

John W. Vinson[MVP]
.