473,394 Members | 1,902 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,394 software developers and data experts.

What may be the reason for Error(VB & MS Access)

20
Hi,

Expand|Select|Wrap|Line Numbers
  1. Dim cn As ADODB.Connection
  2. Dim rs As New ADODB.Recordset
  3. Dim strSQL As String
  4.  
  5. Set cn = New ADODB.Connection
  6. With cn
  7.     .Provider = "Microsoft.Jet.OLEDB.4.0"
  8.     .Open "\\Computer1\Project\SampleDB.mdb"
  9. End With
  10. strSQL = "Update Users set Password='" & txtNewPwd.Text & "' where UserID=" & UserID
  11. cn.Execute strSQL
----------------------------------------------------------------------------------------------------------
"cn.Execute strSQL" statement gives run-time error Message: "ErrorSyntax in Update".

But when i copy the query from VB(on debugging) and execute in MS Access it s geting executed.
What is the reason for this error ?
Mar 2 '07 #1
8 1391
Dear Try this one

With cn
.ConnectionString = "Driver={Microsoft Access Driver (*.mdb)}; DBQ=d:\db1.mdb[Path of db]"

.Open

End With
Mar 2 '07 #2
prileep
20
Dear Try this one

With cn
.ConnectionString = "Driver={Microsoft Access Driver (*.mdb)}; DBQ=d:\db1.mdb[Path of db]"

.Open

End With
I have establed connection with DB using current code itself. Even istarted accessing Database and executing querries. But the error is coming when i execute this particular Update statement only generates run time error.
Mar 2 '07 #3
Killer42
8,435 Expert 8TB
I can't remember the syntax for the SQL Update command, so I'll have to trust you on that.

However, a couple of posibilities come to mind. You might need to put square brackets around your names (Password, for instance, might be a reserved word). You may also need quotes around the User Id (unless UserId field type is numeric). See whether this works...
Expand|Select|Wrap|Line Numbers
  1. strSQL = "Update [Users] set [Password]='" & txtNewPwd.Text & "' where [UserID]='" & UserID &"'"
Also, have you checked that you are putting the correct values in the string, from the UserID variable and the txtNewPwd control? I would recommend you put a breakpoint on the Execute line, and examine the string before executing it. Or do a Debug.Print.

By the way, I think that using the same name for a database field and a variable (UserID in this case) causes unnecessary confusion, and would recommend you avoid it. That's just my opinion, of course. Also, make sure you have VB set to require explicit variable declaration, to ensure you have not accidentally used the wrong name and created a variable instead of referencing an existing one.
Mar 2 '07 #4
prileep
20
I can't remember the syntax for the SQL Update command, so I'll have to trust you on that.

However, a couple of posibilities come to mind. You might need to put square brackets around your names (Password, for instance, might be a reserved word). You may also need quotes around the User Id (unless UserId field type is numeric). See whether this works...
Expand|Select|Wrap|Line Numbers
  1. strSQL = "Update [Users] set [Password]='" & txtNewPwd.Text & "' where [UserID]='" & UserID &"'"
Also, have you checked that you are putting the correct values in the string, from the UserID variable and the txtNewPwd control? I would recommend you put a breakpoint on the Execute line, and examine the string before executing it. Or do a Debug.Print.

By the way, I think that using the same name for a database field and a variable (UserID in this case) causes unnecessary confusion, and would recommend you avoid it. That's just my opinion, of course. Also, make sure you have VB set to require explicit variable declaration, to ensure you have not accidentally used the wrong name and created a variable instead of referencing an existing one.
I have used "Option explicit" in my form and it is not giving me any compile time error.
And I have put a break point on assigning query to the variable strSQL.And i am getting the string "Update Users set Password='trustme' where UserID=1". I copied the value from immediate window and executed in MS Access and i found it working fine. But when executing from VB,through ADODB.connection object it is giving me error as i mentioned first.
What is the reason for this ??
Mar 2 '07 #5
vijaydiwakar
579 512MB
I have used "Option explicit" in my form and it is not giving me any compile time error.
And I have put a break point on assigning query to the variable strSQL.And i am getting the string "Update Users set Password='trustme' where UserID=1". I copied the value from immediate window and executed in MS Access and i found it working fine. But when executing from VB,through ADODB.connection object it is giving me error as i mentioned first.
What is the reason for this ??
just alter the column name from password to pwd and try it
ur problem will be get solved
Mar 2 '07 #6
just alter the column name from password to pwd and try it
ur problem will be get solved
Thank you very much for giving solution for this topic.....
Now the table value is updating from my front-end without any error.
But please let me know what is the reason, i am getting error in giving field name as PassWord.
Mar 5 '07 #7
vijaydiwakar
579 512MB
Thank you very much for giving solution for this topic.....
Now the table value is updating from my front-end without any error.
But please let me know what is the reason, i am getting error in giving field name as PassWord.
Dear there are som ereserved words for every backend whenevr u use that word say in oracle then oracle give the error at design time but unfortunatly access not so try not to use them
some word are date,password,name,desc in oracle etc
Good Luck
Mar 5 '07 #8
Killer42
8,435 Expert 8TB
Dear there are som ereserved words for every backend whenevr u use that word say in oracle then oracle give the error at design time but unfortunatly access not so try not to use them
some word are date,password,name,desc in oracle etc
Does Oracle allow them if you put square brackets around them (as I suggested earlier)? For that matter, does Oracle use the square brackets at all?
Mar 5 '07 #9

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

Similar topics

1
by: Vamsi | last post by:
Hi Guys, I have installed Visual Studio.Net on my windows XP machine. First after installing all the required WCU, then installed the Visual Studio.Net. All set up was completed...
0
by: Ivan | last post by:
Visual Basic .NET compiler is unable to recover from the following error: System Error &Hc0000005& (Visual Basic internal compiler error) Save your work and restart Visual Studio .NET....
8
by: erin.sebastian | last post by:
Hi all, I have a really silly problem that i can't find the answer too. I am working with VB.NET and i am trying to insert a new record into my access database (pretty easy right?) well i am...
2
by: bb | last post by:
when using the web deployment project to merge my aspnet assemblies i get an unusual error 'access to path denied' i double checked path looks ok, and gave everyone full perms on the folder and...
2
by: HelenWu | last post by:
I have two frames in index.html: <frameset cols="165,*"> <frame name="NCTnav" src="NCTnavHome.htm" scrolling="auto"> <frame name="NCTmain" src="http://www.yahoo.com"> </frameset> ...
1
by: daraboy | last post by:
I have a Web home page which allows the IIS users account IUSR_Svr01 to view the page. Each link on the home page allows access to a sub folder, the access to the sub folder is restricted by the...
7
by: sforsasi | last post by:
Hi, I'm trying a simple code to upload a file to the server. When I click to Upload I get the following error message: Error: Access to the path xxx is denied The folder in which I'm trying...
4
bhing
by: bhing | last post by:
please help me.. i dont really understand whats happening in my server.... i have a website using php... when i try to access it this is the message.... Fatal error: Access denied for user...
2
by: =?Utf-8?B?U2hhbQ==?= | last post by:
I am having the error when i execute my .net application i got this error. "Access is denied. (Exception from HRESULT: 0x80070005 (E_ACCESSDENIED)) ". Can anyone help me to resolve this error....
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: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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...
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...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

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.