Update a field in a query based on a user input

G

Guest

Hello

Can anybody help me to update a field in a query based on a user input?

I declared an integer variable, intNum.

The user input a number through use of an inputbox

intNum = val(inputbox("Enter the correct number"))

I run a query, qrySelectMember, to select a record from a table, tblMember.
I want to update a tblMember field, SeatNumber, for the selected record whent
the user click a command button, cmdUpdateSeatNumber.

Any help will be appreciated,

TIA,
RT
 
D

Dale Fye

RT,

How do you know what the current record is, I assume that the query or table
that is the recordsource for your form has an ID field of some sort? You
indicate you have a query, and a variable, why would you use in inputbox
rather than a textbox on your form?

The SQL for a query which is run from a command button on a form, containing
a control that contains the seat number (txtSeatNumber), and where the forms
recordsource contains an ID field would look something like:

UPDATE tblMember
SET SeatNumber = me.txtSeatNumber
WHERE tblMember.ID = me.ID

HTH
Dale
 
J

John Vinson

Hello

Can anybody help me to update a field in a query based on a user input?

I declared an integer variable, intNum.

The user input a number through use of an inputbox

intNum = val(inputbox("Enter the correct number"))

I run a query, qrySelectMember, to select a record from a table, tblMember.
I want to update a tblMember field, SeatNumber, for the selected record whent
the user click a command button, cmdUpdateSeatNumber.

Any help will be appreciated,

TIA,
RT

Whoa.

You're taking five steps to do what can be done in two!


UPDATE tblMember
SET SeatNumber = Forms!frmYourForm!txtSeatNumber;

Enter the seat number in the textbox txtSeatNumber and execute this
query (in the command button's Click event or in
txtSeatNumber'sAfterUpdate event).

No prompt, very little code needed!

One question though: is a seat number a proper attribute of a Member
table? Does a member have one, and only one, seat?

John W. Vinson[MVP]
 
G

Guest

Thanks, John! Both codes from you and Dale work correctly. To answer your
question, the system has three simple tables:

tblMember has demographic information of the members.

tblEvent has event's information.

tblReservation is the junction table between tblMember and tblEvent.
SeatNumber is one of the fields in tblReservation. If a member reserves
three tickets, then the operator will find a consecutive open seats for the
member. If consecutive seats are not available, then individual seats must
be assigned to the member.

Thanks again for your help.

RT
 

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

Top