A Microsoft Office (Excel, Word) forum. OfficeFrustration

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

Go Back   Home » OfficeFrustration forum » Microsoft Access » Running & Setting Up Queries
Site Map Home Register Authors List Search Today's Posts Mark Forums Read  

Update a field in a query based on a user input



 
 
Thread Tools Display Modes
  #1  
Old July 5th, 2005, 01:26 AM
RT
external usenet poster
 
Posts: n/a
Default Update a field in a query based on a user input

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

  #2  
Old July 5th, 2005, 03:54 AM
Dale Fye
external usenet poster
 
Posts: n/a
Default

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


"RT" wrote in message
...
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




  #3  
Old July 5th, 2005, 05:54 AM
John Vinson
external usenet poster
 
Posts: n/a
Default

On Mon, 4 Jul 2005 17:26:01 -0700, "RT"
wrote:

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]
  #4  
Old July 6th, 2005, 09:05 PM
RT
external usenet poster
 
Posts: n/a
Default

Thanks, Dale! Both codes from you and John work correctly.

"Dale Fye" wrote:

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


"RT" wrote in message
...
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





  #5  
Old July 6th, 2005, 09:10 PM
RT
external usenet poster
 
Posts: n/a
Default

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

"John Vinson" wrote:

On Mon, 4 Jul 2005 17:26:01 -0700, "RT"
wrote:

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]

 




Thread Tools
Display Modes

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

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Many-to-many implementation problem Al Williams Database Design 15 April 29th, 2005 05:19 PM
Update field value automatically based on subform Sammie Using Forms 0 February 11th, 2005 09:49 PM
update queries and forms Mary Pode Database Design 16 February 2nd, 2005 05:25 PM
Office 2003 installation problem, log file attached.... Ryan Setup, Installing & Configuration 0 January 20th, 2005 06:57 PM
Here's a shocker Mike Labosh General Discussion 2 October 26th, 2004 05:04 PM


All times are GMT +1. The time now is 03:56 AM.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 OfficeFrustration.
The comments are property of their posters.