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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Dynamically choosing a table via form control to insert a record

Status
Not open for further replies.

dreew

Programmer
May 16, 1999
15
0
0
US
This one has been bugging me for some time.<br>
<br>
I'd like to determine which table to insert a record into after validation of the entered values, and based upon one of the user's selections on the form. It seems like a reasonable action, but I'm still a novice at sql, so have chewed my fingernails for too long.<br>
<br>
Any thoughts?
 
Assuming that you only want to insert records try this:<br>
<br>
- Make a form without attaching any tables or queries to it<br>
- Place and name the textfields you need on the form (e.g. txtInputField1, txtInputField2)<br>
- Place a command button and insert your code to On Click<br>
- Make your cases creatively using If...then and/or Select...Case programming<br>
- Make append queries to insert data from form to different tables. You can put the whole sql in code or just the run code which runs saved append queries<br>
<br>
The general syntax is:<br>
INSERT INTO Table1 (tableFields) VALUES (formFields) <br>
which in Access turns into:<br>
INSERT INTO Table1 (Field1, Field2...) SELECT [Forms]![frmInputForm]![txtInputField1], [Forms]![frmInputForm]![txtInputField2]...;<br>
<br>
Good luck,<br>
Al
 
Thank you for your response.<br>
<br>
Is there a way for the 'INSERT INTO Table1... ' portion of the example to be similar to 'INSERT INTO [Forms]![frmInputForm]![txtInputField1] (interpreted by SQL as a table])'<br>
<br>
Perhaps I could dim a table variable and assign the form control to that variable...<br>
<br>
Still troubled...<br>
Drew<br>

 
WOOHOO!! <br>
<br>
After a couple more hours, I finally made that dang bird fly...Thanx for pointing me in the right direction, Al.<br>
<br>
Happy holidays,<br>
Drew
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top