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

User form txt box to update database

Status
Not open for further replies.

anthony777

Programmer
Nov 8, 2008
24
US
I have a form with txtboxes that the user is going to enter I need the data they entered to fill the table. I know I should know this but slipping my mind now lets say one txt box is custid once they enter I need that to fill the database table.

Thank You
 
Assume the form is unbound. Create a command button and execute a SQL UPDATE statement in its OnClick() event.

Cogito eggo sum – I think, therefore I am a waffle.
 

going by memory, so I hope I have the syntax correct...if anything I messed up the quotes....


dim strsql as string

strsql = "insert into Table1(CustID)"
strsql = strsql + "Values(" & me.text1 & ")"

docmd.RunSQL strsql
 
Zigs - you need a space between (CustID) and Values.

Cogito eggo sum – I think, therefore I am a waffle.
 
Hi Everyone,

I have done the following code below and it works fine(NEW CUST field is a text field).

The only problem that I have is that after I enter information into the field I get a parameter value pop up Box(I have to enter information again and then it copies the the info to the table.

I would like just to type one time and update the table.

What am I doing wrong?

Private Sub Command34_Click()
Dim strsql As String
strsql = "insert into GRABCUST (Name)"
strsql = strsql + "Values (" & Me.NEWCUST & ")"
DoCmd.RunSQL strsql

End Sub
 
Put in a space in your SQL after (Name). Enclose Me.NEWCUST in single quotes.

Cogito eggo sum – I think, therefore I am a waffle.
 
Name" is a horrible name for an object that has a name property. You should name the field "CustName" or something similar to avoid issues. If you can't, consider enclosing the field name in []s.

I expect the field is text which requires your code to include quotes around the value:
Code:
Private Sub Command34_Click()
    Dim strsql As String
    strsql = "insert into GRABCUST ([Name]) "
    strsql = strsql + "Values (""" & Me.NEWCUST & """)"
    DoCmd.RunSQL strsql
End Sub
I would also rename Command34 to something like "cmdInsertCust".

Duane
Hook'D on Access
MS Access MVP
 
Thanks Everyone!


This is what I did below and it works like a charm.

Private Sub cmdaddncust_Click()
Dim strsql As String
strsql = "insert into GRABCUST ([CustName]) "
strsql = strsql + "Values (""" & Me.NEWCUST & """)"
DoCmd.RunSQL strsql

Me.NEWCUST.Value = Null
End Sub
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top