By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
454,226 Members | 1,435 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 454,226 IT Pros & Developers. It's quick & easy.

Text Box to Table

100+
P: 158
How would i go about taking the text out of txt1 and place it in a table with a column header textbox1 when i press cmd1

Thanks!
Aug 15 '08 #1
Share this Question
Share on Google+
9 Replies


Expert 100+
P: 112
There are a few ways you could do it, but I would probably place this into the click event for the button:
Expand|Select|Wrap|Line Numbers
  1.     DoCmd.RunSQL "INSERT INTO tablename (textbox1) SELECT '" & me.txt1 & "'";
  2.  
Aug 15 '08 #2

100+
P: 158
There are a few ways you could do it, but I would probably place this into the click event for the button:
Expand|Select|Wrap|Line Numbers
  1.     DoCmd.RunSQL "INSERT INTO tablename (textbox1) SELECT '" & me.txt1 & "'";
  2.  
Thanks for the help that worked wonderfully. Now my next question is how do i get a name from a query to the textbox?
Aug 15 '08 #3

Expert 100+
P: 112
It depends on the query, could you post the sql for your query and I'll incorporate that into an example on how to do it.
Aug 17 '08 #4

100+
P: 158
It depends on the query, could you post the sql for your query and I'll incorporate that into an example on how to do it.
Here is the query

SELECT MasterZip.Territory AS Territory, Count(MasterZip.[ZIP Code]) AS [CountOfZIP Code], Sum(MasterZip.MVRs) AS SumOfMVRs, Sum(MasterZip.Outlets) AS SumOfOutlets
FROM MasterZip
GROUP BY MasterZip.Territory
HAVING (((Left([MasterZip].[Territory],4))=[Please enter the Territory Number]));
Aug 18 '08 #5

Expert 100+
P: 112
I should also have asked, what field are you interested in populating the textbox with?
Aug 18 '08 #6

100+
P: 158
I should also have asked, what field are you interested in populating the textbox with?
the textbox names are txtTerritory, txtMVR, txtOutlets. Is this what you're talking about?
Aug 18 '08 #7

Expert 100+
P: 112
Using a parameterized query makes this difficult, but typically if all you are returning is one value then I find a dlookup the best way to go. A dlookup takes two required parameters and one optional. The first is the field that contains the value you are interested in, the second is the table or query the field is contained within, and the the third is an optional criteria, it then returns the value from the field you specified in the first argument based on the result set of the query. In your case you can use your existing query. The only change you would have to make is instead of passing it the parameter of [Please Enter the territory number] you will need to give it that value such as from a textbox or some other input control on the form, then place the value of that control in your HAVING clause
Expand|Select|Wrap|Line Numbers
  1. HAVING (Left([MasterZip].[Territory],4))= RelevantControlValue));
  2.  
Assuming that once this query is constrained to a territory it only returns one record then you can return any value from any of the fields for instance (assume your query is named query1):

Expand|Select|Wrap|Line Numbers
  1. txtTerritory = dlookup("[Territory]","Query1")
  2.  
Aug 19 '08 #8

100+
P: 158
ok I'll give it a try. Thanks!
Aug 19 '08 #9

Expert 100+
P: 112
Let me know if you have questions, there are several simple things that could cause this to fail, so if it doesn't work we can certainly work through that.
Aug 19 '08 #10

Post your reply

Sign in to post your reply or Sign up for a free account.