Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Where to put INSERT INTO

Status
Not open for further replies.

lorirobn

MIS
Joined
Mar 15, 2005
Messages
450
Location
US
Hi,

I have a form that displays fields from a table (tblRoomHeader), using a Select Query as its record source. If field 'CurrentUse' is changed to a particular value, I need to insert a record onto another table, tblGuestRoom (only need to populate one field).

I have not programmed an Insert before on a form.

Can someone please advise the best place to place the insert logic?

And, is it best to have the SQL right in my module, or set up a Query to do this?

I have set up logic to look something like this.
Code:
dim strInsertSQL as string
strInsertSQL = "INSERT INTO tblGuestRoom ( RoomNumber ) " _
& " SELECT tblRoomHeader.RoomNumber FROM tblRoomHeader " _
& " WHERE (((tblRoomHeader.RoomNumber) = '" & RoomNumber & "'));"

Just not sure where to put it or what to do with it!

Thanks in advance for any help,
Lori
 
Hi

You could put the code in the after update event of the control "CurrentUse"

For the sake of inserting one record I do not see any advantage in setting up a querydef, you could jsut execute the SQL using docmd.runsql

eg

docmd.setwarnings false
docmd.runsql strInsertSQL
docmd.setwarnings true

Regards

Ken Reay
Freelance Solutions Developer
Boldon Information Systems Ltd
Website needs upgrading, but for now - UK
 
Hi Ken,

Thanks for your help - I got it working doing exactly what you said. Just out of curiosity, though, why do I need to setwarnings off before the Insert?

Thanks again,
Lori
 
Hi

To suppress Access warning message "You are about to Insert one row ..etc"

Regards

Ken Reay
Freelance Solutions Developer
Boldon Information Systems Ltd
Website needs upgrading, but for now - UK
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top