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

Passing an InputBox Value to a table

Status
Not open for further replies.

proximity

Technical User
Sep 19, 2002
132
GB
Hi,

A nice easy one, hopefully!

I have have an input box into which a user keys in their name. Can Access then stick this value into a table?

Thanks,

--
Steven
 
One way...
Code:
DBEngine(0)(0).Execute("UPDATE YourTableNameHere SET YourFieldNameHere = '" & InputBox(...) & "';")
Although you should probably expand this to make sure the user doesn't cancel, e.g.
Code:
Dim strInput as string
strInput = InputBox(...)
If Len(strInput)>0 Then DBEngine(0)(0).Execute("UPDATE YourTableNameHere SET YourFieldNameHere = '" & strInput(...) & "';")


[pc2]
 
Sure but there are lots of ways to do it. Provide some details. Is there an open form? What opens the inputbox? When do you want it to occur? etc.
 
Hi,

Function TestTypeThing()
DBEngine(0)(0).Execute ("UPDATE tblUserLogOn SET UserID = '" & InputBox("Enter Your Name") & "';")
End Function

I tried the above. No errors get generated, but it doesn't store the value in the table.

Incidentally, I only want to see if this can be done!! I want the functon to run via a command button, ask for some information and then store it in the table. I was in a hurry (!) so neglected to include the above information. Apologies for that.
 
Oops, forgot that you nned a WHERE clause to specify which record in the table you want to update...
Code:
Function TestTypeThing()
DBEngine(0)(0).Execute ("UPDATE tblUserLogOn SET UserID = '" & InputBox("Enter Your Name") & "' WHERE InsertWhere StatementHere;")
End Function
 
My guess is that "Stick it" means insert..

DBEngine(0)(0).Execute ("INSERT INTO tblUserLogOn (UserID) SELECT '" & InputBox("Enter Your Name") & "';")



 
Hi,

Thanks for all your replies. I solved the riddle by using a record set. Here is the code for anyone who may be interested.

Private Sub cmdAddNewItem_Click()
Dim dbCurrentDatabase As DAO.Database
Dim rstRecordset As DAO.Recordset

Set dbCurrentDatabase = CurrentDb
Set rstRecordset = dbCurrentDatabase .OpenRecordset("rstRecordset")

rstRecordset .AddNew
rstRecordset ("Item").Value = Inputbox("What Item do you wish to add?")
rstRecordset .Update
MsgBox ("Thank you, item has been added")

End Sub

The above works exceedingly well!
 
what you will do if user input nothing/press space and press OK?

________________________________________________________
Zameer Abdulla
Help to find Missing people
Do not cut down the tree that gives you shade.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top