Get data from textbox

  • Thread starter Thread starter Maria
  • Start date Start date
M

Maria

I was trying to create a query that allowed me to add a row of data to
a table like this:

INSERT INTO myTable values("text", 1);

except I want to add data to the end of the table without overwritning
anything and also I want to be able to type in the data manually upon
execuition of the query så the values("text", 1) part isn't ok. I
don't know what to write here.

Is this impossible in query mode? I also tried creating a form but (I
know this is a dummy question but I can't find the answer anywhere) how
do I get the text string that the user types into the text box and alot
this value to a variable that I can use in my append query?

I would be so greatful if you could give me a hand with this!

/Maria
 
Maria,

To begin with, in your SQL statement you need to specify in which fields
in the target table the typed-in values will be stored.

On the second question, it's dead easy; assuming you have form MyForm
with controls Text1 and Text2, and taking the first point into account,
your SQL statement would be:

INSERT INTO myTable ( Field1, Field2 )
SELECT [Forms]![MyForm]![Text1], [Forms]![MyForm]![Text2]

HTH,
Nikos
 
Thanks Nikos!
How do I create a new row at the end of the table were the data's
added?

/Maria


Nikos Yannacopoulos skrev:
 
Maria,

You do not need to create a record before you populate it, the query
does it for you.

Note: "at the end" is not a safe bet; by definition, in a Jet table (Jet
is Access's database engine) there is no guarantee of any given order of
tables. As a matter of fact, if there is a Primary Key defined in the
table, there is a very good chance you will see the records ordered on
it - though, again, no guarantee. In Access, whenever you need a table
ordered in a particular way, you should use a query on it and specify
the ordering in it.

HTH,
Nikos
 
Ok, I see... So I think my problem lies in creating the form more then
in the Query now.

I have created a form with the two text fields and a button with an
action on it when clicked but I'm not sure of what to write in the
action. Should I call upon the query from here. How do I save the data
from the text field into variebles?

/Maria



Nikos Yannacopoulos skrev:
 
Oh, I ment to post the code from the action on my button, as far as
I've got in writing it:

Private Sub Addera_Click()
On Error GoTo Err_Addera_Click


DoCmd.GoToRecord , , acNewRec

Exit_Addera_Click:
Exit Sub

Err_Addera_Click:
MsgBox Err.Description
Resume Exit_Addera_Click

End Sub




Maria skrev:
 
IT's all working now!!!

Thankyou so much for your wonderful help.

Never mind my previous posts... i was a bit too quick to post them I
managed to call the query from my form.


Nikos Yannacopoulos skrev:
 
Good! Glad I could help.
IT's all working now!!!

Thankyou so much for your wonderful help.

Never mind my previous posts... i was a bit too quick to post them I
managed to call the query from my form.


Nikos Yannacopoulos skrev:
 
Back
Top