Wrox Programmer Forums
|
Access VBA Discuss using VBA for Access programming.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Access VBA section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old August 22nd, 2006, 06:46 AM
Registered User
 
Join Date: Aug 2006
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
Default How to get value from field??

Hi,
    I am creating a form that allow users to change their login password. The 2 fields name user input to are txtPassword and txtName . But it is not working. Pls kindly help. Thnks.

Private Sub Command0_Click()
Dim SQL As String
DoCmd.SetWarnings False
DoCmd.RunSQL "UPDATE [EmpTable] SET [EmpTable].[EmpPassword] = Me.txtPassword.value WHERE (((EmpTable.EmpName) = Me.txtName.value))"
DoCmd.SetWarnings True
End Sub


 
Old August 22nd, 2006, 06:55 AM
Friend of Wrox
 
Join Date: Mar 2004
Posts: 3,069
Thanks: 0
Thanked 10 Times in 10 Posts
Default

More than likely the problem is that you are trying to pass values to the SQL string at run time. This is a big no no in Access. Try this modification:

'----------
Private Sub Command0_Click()

Dim sPass As String
Dim sName As String
Dim sSQL As String

sPass = Me.txtPassword
sName = Me.txtName

sSQL = ""UPDATE [EmpTable] SET [EmpTable].[EmpPassword] = " & sPass & " WHERE (((EmpTable.EmpName) = " & sName & "))"

DoCmd.SetWarnings False
DoCmd.RunSQL sSQL
DoCmd.SetWarnings True
End Sub
'----------


Did that work?




mmcdonal
 
Old August 22nd, 2006, 06:58 AM
Friend of Wrox
 
Join Date: Mar 2004
Posts: 3,069
Thanks: 0
Thanked 10 Times in 10 Posts
Default

P.S. SQL is a reserved word in some cases. It is always best to prefix your variables with some notation of type, as you have done with your text boxes.

mmcdonal
 
Old August 22nd, 2006, 08:02 PM
Registered User
 
Join Date: Aug 2006
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
Default

it worked. Thnks alot.






Similar Threads
Thread Thread Starter Forum Replies Last Post
Replace Gridview field if null with new field Indo77 ASP.NET 2.0 Basics 1 June 18th, 2007 06:22 AM
Fill field based on another field skwilliams Classic ASP Basics 3 December 30th, 2006 11:02 AM
Updating a Date field based on another field arholly Access VBA 6 November 22nd, 2006 11:19 AM
Copy previous field record if next field is null ecampos Access VBA 6 June 23rd, 2006 12:55 PM
Update city field based on zip field nganb SQL Server ASP 0 April 22nd, 2004 10:30 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.