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!

help: write from textbox to underlying table 2

Status
Not open for further replies.

TKSlayer

Technical User
Jan 28, 2004
18
0
0
US
Hello all,

I'm trying to use a textbox with command button beside it to input text and then click button the text in the box to an underlying table. Problem is, I can't get it to work. I thought an append query would be the easiest way...however, a friend told me a simple macro would work. Problem is I don't know what programming language he was speaking of. So, my question, what is the best way to accomplish this? ADO? VB? SQL?
 
You could use any combination of the above.

The VB + DAO would be the easiest. I use DAO because it is compatible with 97 (and I'm used to it).

In your buttons on click event you could add this code:


Dim db As DAO.Database
Dim rs As DAO.Recordset
Set db = CurrentDb
Set rs = db.OpenRecordset("YourTable")
rs.AddNew
rs!YourTableFieldName = Me.YourTextBoxName
rs.Update
Set rs = Nothing
Set db = Nothing


You will need a reference to the DAO3.X object library.

HTH,
Eric
 
The easiest way to perform this task is:

In the event procedure of the OnClick event for the command button, enter this code...


Dim strSQL as string
strSQL = "INSERT INTO yourTable ([yourCol]) VALUES (" & Me.yourTextBox & ");"

DoCmd.RunSQL strSQL
 
Gave the SQL string a try since it seemed a bit more simple (I had experience with some inner and outer joins using SQL earlier in this database)...however, I am getting something weird popping up. My table is tblTO and my column heading is "F1"

Private Sub Command5_Click()
Dim strSQL As String
strSQL = "INSERT INTO tblTO ([F1]) VALUES (" & Me.Text15 & ");"
DoCmd.RunSQL strSQL
MsgBox "New T.O. has been added to the Master List!", vbOKOnly, ADDED
DoCmd.Close acForm, "frmADD", acSaveYes
DoCmd.OpenForm "frmMAIN", acNormal, , , acFormPropertySettings, acWindowNormal
End Sub

When I run this, a window pops up with the text from the textbox displayed and states: Enter Parameter value...then it has a blank space to enter stuff in. It is caught in an infinite loop as well for if you enter text into this blank...it won't close the parameter pop up for anything. Any suggestions?
 
Hi!

Does text15 contain a value when you try to run this?

Try testing it with the isnull function.

Might also be wrong datatype, if it is text, then:

[tt]...VALUES ('" & Me!Text15.Value & "');"[/tt]

- apostrophe (') text qualifiers.

Roy-Vidar
 
Great!

Works like a top...However, the append notification pops up before my message box. Is there a hidden option for this? I'd just like the message box to pop notifying them that the append has happened...that way they don't have control over whether or not the change happens...just notification that it has, know what I mean? If there isn't a way to hide that append notification...it's cool, I'll deal :p Thanks for all the help everyone!
 
Hi again!

[tt]docmd.setwarnings false
docmd.runsql....
docmd.setwarnings true[/tt]

- essential to remember setting the warnings to true afterwards, else it would be the equivalence of turning off all warnings... (oups where are all my tables;-))

Roy-Vidar
 
Thanks again! I should have known the answer to that...I think I've been going to strong on the code for this because I'm starting to get numb...

Thanks for waking me up :)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top