473,406 Members | 2,378 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,406 software developers and data experts.

recordset problem: expression not defined in context

I am opening a form to allow the user to change names contained in a child table (multiple records)
and having the user enter the old name and the new name

Code below fails. NamePhone in the table projects - says its not defined in context - and yet that is the name of the field in the table projects. I am assuming its just something I have missed.

Expand|Select|Wrap|Line Numbers
  1. Private Sub cmdNewName_Click()
  2.     Dim rsProjects As ADODB.Recordset
  3.     Dim strSQL As String
  4.  
  5.     Set conDatabase = CurrentProject.Connection
  6.     strSQL = "SELECT * FROM Projects WHERE NamePhone =" & oldname
  7.  
  8.     Set rsProjects = New ADODB.Recordset
  9.        rsProjects.Open strSQL, CurrentProject.Connection, adOpenKeyset, adLockOptimistic
  10.  
  11.     With rsProjects
  12.         Do While Not .EOF
  13.             !NamePhone = Newname
  14.             .Update
  15.             .MoveNext
  16.         Loop
  17.     End With
  18.  
  19.  
  20.     rsProjects.Close
  21.     conDatabase.Close
  22.     Set rsProjects = Nothing
Apr 5 '13 #1
9 6211
TheSmileyCoder
2,322 Expert Mod 2GB
Start by making sure at the top of your module you have the line:
Expand|Select|Wrap|Line Numbers
  1. Option Explicit
Exactly which line is failing?
Apr 5 '13 #2
Rabbit
12,516 Expert Mod 8TB
If NamePhone is a string, then you need to surround its values in quotes.
Apr 5 '13 #3
line 9 rsprojects.open fails but NamePhone has no values when I put a watch on it
Apr 6 '13 #4
Expand|Select|Wrap|Line Numbers
  1.     rsProjects.Open strSQL, CurrentProject.Connection, adOpenKeyset, adLockOptimistic
fails
"namePhone" is a field in a projects table
Apr 6 '13 #5
Tried
Expand|Select|Wrap|Line Numbers
  1. Option Explicit 
and got an error on that line. Where should I put Option Explicit?
Apr 6 '13 #6
I put a watch on NamePhone and the value error is <Expression not defined in context> type empty form_nameform.cmdNewName_Click

NamePhone is a field on the table Projects. Do I need to open this table explicitly? I have not done that before in these routines that I have run.
Apr 6 '13 #7
Rabbit
12,516 Expert Mod 8TB
Did you try my suggestion?
Apr 7 '13 #8
yes of course - error continues
Apr 8 '13 #9
Rabbit
12,516 Expert Mod 8TB
And what does your newly modified code look like?
Apr 8 '13 #10

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

Similar topics

8
by: Dima Protchenko | last post by:
Hi, guys. Please help if you know something about this. Error: ADODB.Recordset error '800a0e78' Operation is not allowed when the object is closed. line: if not rs.EOF then (from the code...
5
by: Tom van Stiphout | last post by:
Hi all, I'm seeing a weird problem I'm thinking might be due to corruption. What do you think? Here is the relevant code, which is in a standard module, called from subfrmDetail's...
1
by: Khurram Hanif | last post by:
I've a pre-written application using ASP with ADO. Recordset used in the application to update database. When i try to add a record it shows error like "Microsoft JET Database Engine (0x80040E09)...
3
by: | last post by:
Hello ppl, I have snippet that works fine udner ADODB with VB6, but something wrong with it in Vb.NET. Anyone can help? Recordset1 (ADODB.Recordset) Error: Arguments are of the wrong type, are...
10
by: LucaBrasi | last post by:
I am using a DAO recordset based on a table on the back end, and the table has almost 11,000 rows. Is there a way to 'filter' the table to use only the rows that meet my criteria ? I know I could...
2
by: Bobby | last post by:
Hello, I have an application which uses a SQL server 2003 Back end and an Access 2003 front end. I am trying to populate a recordset in the FE with data from an ODBC linked table to the BE....
0
by: Yarik | last post by:
Hello, Here is a sample (and very simple) code that binds an Access 2003 form to a fabricated ADO recordset: ' Create recordset... Dim rs As ADODB.Recordset: Set rs = New ADODB.Recordset '...
3
by: Dilruba | last post by:
I want to create a Recordset and after that start a loop and within that loop i am creating more other recordset. But Recordset within the loop is not working properly i.e. they are not getting...
12
by: =?Utf-8?B?R1ROMTcwNzc3?= | last post by:
Hi Guys, me again!!!! I've got a little recordset problem, basically I'm trying to build a jobs by email feature, so I have the following - Jobs by Email table which includes - category...
1
by: shariquekhan | last post by:
I am using Windows forms in .NET 2.0. I have used Split Container in my application. And I am also using two Context Menus. I want that one context menu is associated with panel1 of split container &...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
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...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new...

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.