473,507 Members | 9,611 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Access 2002 / 2003 Function Compatability

5 New Member
Hi Folks,
I've produced an Access application that reads the users login name from their environmental settings and then acquires their full name and department from the "Startup" table, to display on their startup screen (Code shown below).

While this works satisfactorily in Access 2002 on any windows platform, it falls down on Access 2003.

When debugging I get [Run-Time Error "2001" You cancelled previous operation], and have no idea why.

The line Marked "***" is where the debugger pulls up the error (Admin Edit - Line #13).

Any pointers would be greatfully recieved.

Thanks
Phil
--------------------------------------------------
Expand|Select|Wrap|Line Numbers
  1. Public Sub Form_Load()
  2.  
  3. Dim RSstr As String
  4. Dim Uname As String
  5. Dim Udept As String
  6. Dim Utitle As String
  7. Dim N_Name As String
  8. Dim Slevel As Integer
  9.  
  10. N_Name = Environ("Username")
  11.  
  12.  
  13. ** If IsNull(DLookup("[Users_Name]", "Startup", "[Network_Name] = N_name")) Then
  14.     Uname = "Operator"
  15.     Udept = "Unknown"
  16.     Utitle = "Unknown"
  17.     Slevel = 5
  18. Else
  19.     RSstr = "SELECT * FROM Startup Where [Network_Name] = " & "'" & N_Name & "'"
  20.     Me.RecordSource = RSstr
  21.     Uname = [Users_Name]
  22.     Udept = [Dept]
  23.     Utitle = [Job_Title]
  24.     Slevel = [Sec_Level]
  25.     NTstr = Uname & " - " & Utitle
  26.  
  27. End If
  28.  
  29.  
  30. End Sub
Jan 21 '08 #1
4 1676
PianoMan64
374 Recognized Expert Contributor
Hi Folks,
I've produced an Access application that reads the users login name from their environmental settings and then acquires their full name and department from the "Startup" table, to display on their startup screen (Code shown below).

While this works satisfactorily in Access 2002 on any windows platform, it falls down on Access 2003.

When debugging I get [Run-Time Error "2001" You cancelled previous operation], and have no idea why.

The line Marked "***" is where the debugger pulls up the error.

Any pointers would be greatfully recieved.

Thanks
Phil
--------------------------------------------------
Expand|Select|Wrap|Line Numbers
  1. Public Sub Form_Load()
  2.  
  3. Dim RSstr As String
  4. Dim Uname As String
  5. Dim Udept As String
  6. Dim Utitle As String
  7. Dim N_Name As String
  8. Dim Slevel As Integer
  9.  
  10. N_Name = Environ("Username")
  11.  
  12.  
  13. ** If IsNull(DLookup("[Users_Name]", "Startup", "[Network_Name] = N_name")) Then
  14. Uname = "Operator"
  15. Udept = "Unknown"
  16. Utitle = "Unknown"
  17. Slevel = 5
  18. Else
  19. RSstr = "SELECT * FROM Startup Where [Network_Name] = '" &  N_Name & "'"
  20. Me.RecordSource = RSstr
  21. Uname = [Users_Name]
  22. Udept = [Dept]
  23. Utitle = [Job_Title]
  24. Slevel = [Sec_Level]
  25. NTstr = Uname & " - " & Utitle
  26.  
  27. End If
  28.  
  29.  
  30. End Sub
  31.  
The reason is because the N_Name variable is not outside the Critieria string of your DLOOKUP function. If it returns a null, then the procedure is cancelled. that is why you're getting the Run-Time Error 2001. You can either select the second half of your if statement, and get rid of the Dlookup, or just simple use the .NoMatch option available is DAO to see if you've found the record or not and test on that.

If you change the dlookup line of code to say the following:

Expand|Select|Wrap|Line Numbers
  1.  
  2.         DLookup("[Users_Name]", "Startup", "[Network_Name] ='" & N_Name & "'))
  3.  
  4.  
Expand|Select|Wrap|Line Numbers
  1. Public Form_Load()
  2.        Dim RSstr As String
  3.        Dim Uname As String
  4.        Dim Udept As String
  5.        Dim Utitle As String
  6.        Dim N_Name As String
  7.        Dim Slevel As Integer
  8.        Dim MyDB as DAO.Database
  9.        Dim MyRS as DAO.Recordset
  10.  
  11.  
  12.        N_Name = Environ("UserName")
  13.  
  14.        Set Mydb = CurrentDB()
  15.        Set MyRs = MyDB.OpenRecordSet("SELECT * FROM Startup WHERE Nework_Name = '" & n_Name & "'",dbOpenSnapshot)
  16.  
  17.         With MyRS
  18.                 If Not .NoMatch Then
  19.                          Set me.RecordSource = MyRS
  20.                          Uname = [Users_Name]
  21.                          Udept = [Dept]
  22.                          Utitle = [Job_Title]
  23.                          Slevel = [Sec_Level]
  24.                          NTstr = Uname & " - " & Utitle
  25.                 Else
  26.                          Uname = "Operator"
  27.                          Udept = "Unknown"
  28.                          Utitle = "Unknown"
  29.                          Slevel = 5
  30.                  End if
  31.        End With
  32.    MyRS.Close
  33.    MyDB.Close
  34. End Sub
  35.  
Jan 22 '08 #2
NeoPa
32,557 Recognized Expert Moderator MVP
If you look at your line #13...
Expand|Select|Wrap|Line Numbers
  1. If IsNull(DLookup("[Users_Name]", "Startup", "[Network_Name] = N_name")) Then
... you will see the string "[Network_Name] = N_name" is used as the third parameter. If you use ...
Expand|Select|Wrap|Line Numbers
  1. Debug.Print "[Network_Name] = N_name"
... you will see the results are exactly as you would expect ([Network_Name] = N_name). What you intend however, is something of the form of ...
[Network_Name] = 'JonesR'
To get this you need to formulate the string from the data in your variable BEFORE passing it across to the DLookup() function.
Expand|Select|Wrap|Line Numbers
  1. If IsNull(DLookup("[Users_Name]", "Startup", "[Network_Name] = '" & N_name & "')) Then
Essentially you want to search the table for whatever's in your variable N_name - rather than always to search for the string N_name (in fact, as it's not delimited, it wouldn't even recognise it as a string, but some spurious reference instead).
Jan 22 '08 #3
Bod
5 New Member
Thank you for your help folks

Phil
Jan 23 '08 #4
NeoPa
32,557 Recognized Expert Moderator MVP
No problems Phil.
I hope it all helped :)
Jan 23 '08 #5

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

Similar topics

3
1602
by: Larry Pits | last post by:
Hi All, Is there a backward compatability issue regarding to .Net 2002 and .Net 2003? I heard someone said that if you're developing in .Net 2003 and gave the entire project to someone who is...
13
2620
by: Noesis Strategy | last post by:
When I ordered my new laptop, Sony didn't offer Access 2003 in its bundles. Recently, I have begun to design Access databases using an copy of Access 2002 from my previous laptop. It works fine,...
6
4712
by: Peter Frost | last post by:
Please help I don't know if this is possible but what I would really like to do is to use On Error Goto to capture the code that is being executed when an error occurs. Any help would be much...
2
2405
by: MFS 43 | last post by:
If the front end of a database is in Access 2002 or 2003, can the backend be in Access 2000 or does the backend have to be converted to a later version?
4
7135
by: Br | last post by:
We're using an Access2000 ADP with an SQL2000 back-end. Because SQL2000 was released after Access2000 you need to be running Access2000 SP1 (2 or 3) for it to work properly. Is there an easy way...
3
1636
by: Richard Cleaveland | last post by:
A client has just successfully upgraded from Access 97 to 2000. I don't have Access 2000, but I do have Office XP. Can I successfully use my Access on their database? They kind of did this...
52
9914
by: Neil | last post by:
We are running an Access 2000 MDB with a SQL 7 back end. Our network guy is upgrading to Windows Server 2003 and wants to upgrade Office and SQL Server at the same time. We're moving to SQL Server...
10
2158
by: Bobby | last post by:
Hi, The organisation I work for is on the verge of buying Microsoft Office 2007 Pro Plus OLP NL. We currently use Office Pro 2003. Our business system is written in Access 2003 with a SQL Server...
0
2726
by: Sebastian | last post by:
Hello I develop my applications in Access 2002. My development system is running Windows XP SP2 and I have Microsoft Office XP Developer. Microsoft Office XP is at SP3. I used Inno Setup (great...
0
7110
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
7314
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
7372
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...
1
7030
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
7482
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
1
5041
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...
0
4702
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
1540
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
758
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.