473,379 Members | 1,367 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,379 software developers and data experts.

How to insert value into database

I am writing a code to copy and insert any value that is inserted in the field FormUsername but when I run this, I got an error.

can anyone help


Expand|Select|Wrap|Line Numbers
  1. Private Sub CopyRecord()
  2. Dim sSql As String
  3.  
  4. sSql = "INSERT INTO WelcomeTemp ([UserLog],) " & _
  5.         "VALUES (" & WelcomeScreen![FormUsername] & ");"
  6.  
  7. CurrentDb.Execute sSql, dbFailOnError
  8.  
  9. End Sub
May 18 '11 #1
8 7916
Mariostg
332 100+
Coma aftr UserLog...
Also need single quotes surrounding the string to insert...
May 18 '11 #2
Lysander
344 Expert 100+
Could you please tell us what the error message is, and what version of Access you are using.

I tried your code, modified for my table, and got the error "Syntax Error in Insert Command"

I have not seen your syntax before.
Ah, having just done a goggle search, I think the VALUES is new to Access 2007, I have never seen it in earlier versions (And have not used 2007 myself)

What could be an issue is what sort of field UserLog is. I suspect it is a string field, in which case, you are missing the quotes around FormUserName.

Try this. (I can't test it as I don't have Access 2007

Expand|Select|Wrap|Line Numbers
  1. sSql = "INSERT INTO WelcomeTemp ([UserLog]) " & _
  2. "VALUES ('" & WelcomeScreen![FormUsername] & "');
  3.  

Example from Microsofts Help Page, note the quotes around the values

Expand|Select|Wrap|Line Numbers
  1.     dbs.Execute " INSERT INTO Employees " _
  2.         & "(FirstName,LastName, Title) VALUES " _
  3.         & "('Harry', 'Washington', 'Trainee');"
  4.  
May 18 '11 #3
This is the full code.
I am getting a Run-time error '424' Object required

In fact, all that i want is to record the username in when Login was successful, so i will recall the value from the tblWelcomeTemp fldUserLog and display it in the next form after the login,

Does anyone have a suggestion

Expand|Select|Wrap|Line Numbers
  1. Private Sub CopyRecord()
  2. Dim sSql As String
  3.  
  4. sSql = "INSERT INTO WelcomeTemp.table ([UserLog]) " & _
  5.         "VALUES ('" & WelcomeScreen.Form![FormUsername] & "') where WelcomeTemp[MyID] =1;"
  6.  
  7. dbs.Execute sSql, dbFailOnError
  8.  
  9. End Sub
  10.  
  11.  
  12. Private Sub FormUsername_AfterUpdate()
  13.   If Me.NewRecord Then Exit Sub
  14.     Call CopyRecord
  15. End Sub
May 19 '11 #4
Mariostg
332 100+
Why did you change WelcomeScreen![FormUsername] to this WelcomeScreen.Form![FormUsername]

If you try to compile it, you will see that the object WelcomeScreen does not exists.
May 19 '11 #5
NeoPa
32,556 Expert Mod 16PB
When you've sorted out the VBA problems in your code, you will need to look at your use of the WHERE clause in your SQL. INSERT INTO has no WHERE clause. Indeed, it would make little sense if you think about it.

Lysander,
Actually the VALUES() reference has been around for a while (Pre 2003 at least), but finding info about it has never been very easy. Check out Finding Jet SQL Help for a pretty good list of the syntax for all the SQL commands available to Access.
May 19 '11 #6
Lysander
344 Expert 100+
Thanks NeoPa, I had never seen it before outside of SQL-Server, learnt something new.
May 19 '11 #7
Problem completely solved..thank you for your assistance
Jun 17 '11 #8
NeoPa
32,556 Expert Mod 16PB
Well done Walid. Pleased to hear it :-)
Jun 17 '11 #9

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

Similar topics

3
by: Chris Gilbert | last post by:
I'm quite stuck with this: I have an import table called ReferenceMatchingImport which contains data that has been sucked from a data submission. The contents of this table have to be imported...
2
by: ven | last post by:
Hello i have two tables in my MS SQL named table1 and table2. In each table i have a column PRICE with my own datatype decimal 14;4 allows nulls.... now i wanna select from one table to second...
6
by: Frederik Vanderhaeghe | last post by:
Yo, I have a problem inserting into my database. When i try the following: "INSERT INTO TBL_Bestanden_Zoeken (Id,docnr,klnr,klnaam,datum,bedrag,type) VALUES...
5
by: Steph | last post by:
hello everyone, I would to know how to check the value I am getting from an HTML form. Let's put it that way, I need to get a string and I would like to make sure this is a string and not a...
2
by: krajah | last post by:
Need Help Here....... I'm using visual C#: How to insert the value that user have entered combobox and click button.The value will sent into database.This is in form1. In form2,if click button...
1
Fary4u
by: Fary4u | last post by:
Hi is any body know where is actual problem is coz it's look me some problem ? to insert value into the MS ACCESS DATABASE after the value is true form html <input type="checkbox"...
2
by: noriko | last post by:
Hello, I have a table with 4 fields. I want to insert value into one of the fields, based on If condition of other fields... Company1, Company2, Company3, NoOfCompanies xxx,,, xxx,xxx,,...
1
by: ghjk | last post by:
I'm a new to postgres. i have a table which is having a colomn with auto increment value. When I insert value to that table, it gives an error. First column is the auto increment one....
2
by: digituf | last post by:
i have 2 forms here. 1) DisplayDetails.php 2) RegistrationForm.php when user click to the link 'Next' at the DisplayDetails.php page it will bring all the session value to the...
6
by: aeris | last post by:
Sorry to bothering you all. Can someone give me a hand here? How to insert value from a form into a class? I have a form, called EnterKeyWindow.cs. public CarrierFile carrierFile; ...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.