Solved

code error

Posted on 2002-05-04
8
170 Views
Last Modified: 2010-05-02
i cannot seem to get this to work! can anyone help? i found it from a question by nod31

Function DeleteUser()
    dim SQL as String
    datEmployees.RecordSource = SQL
    SQL = ("Select * from Employees where Admin = true")

If SQL.RecordCount > 1 Then

MsgBox "You can delete the user!"

Else

MsgBox "cannot delete last administrator"

End If
datEmployees.RecordSource = "Employees"
End Function

cheer :)
0
Comment
Question by:stevenglass
8 Comments
 
LVL 1

Accepted Solution

by:
baltman earned 50 total points
ID: 6989878
I Think that in this part of the function:

   dim SQL as String
   datEmployees.RecordSource = SQL
   SQL = ("Select * from Employees where Admin = true")

The datEmployees.RecordSource is undefined, since the value is not assigned to string variable SQL until after that. Try putting SQL = ("Select ... true") one line higher:

   dim SQL as String
   SQL = ("Select * from Employees where Admin = true")
   datEmployees.RecordSource = SQL

Just an idea....:o)

BA
0
 

Author Comment

by:stevenglass
ID: 6989914
doesn't work! :(

i get a type mismatch on this line!

If SQL > 1 Then
0
 
LVL 75

Expert Comment

by:Anthony Perkins
ID: 6989939
baltman is on the right track, but since you are using a Data Control you probably need to do a refresh.  So the code should look as follows:

Dim SQL as String
SQL = "Select * from Employees where Admin = true"
datEmployees.RecordSource = SQL
datEmployees.Refresh

Also, please maintain your open questions:
file transfers Date: 12/01/2001 01:17PM PST
http://www.experts-exchange.com/jsp/qShow.jsp?ta=delphi&qid=20242701
queue's Date: 04/04/2002 12:51PM PST
http://www.experts-exchange.com/jsp/qShow.jsp?ta=java&qid=20285021
design a new network Date: 05/10/2001 03:01PM PST
http://www.experts-exchange.com/jsp/qShow.jsp?ta=networkgen&qid=20116385

Thanks,
Anthony
0
Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

 
LVL 1

Expert Comment

by:hiranmaya
ID: 6990849
Dim SQL as String
'If admin is string variable then no type mismatch
SQL = "Select * from Employees where Admin = 'true'"
0
 
LVL 3

Expert Comment

by:carruina
ID: 6990933
I think you must change

Dim SQL as String
SQL = "Select * from Employees where Admin = true"
datEmployees.RecordSource = SQL
datEmployees.Refresh

if datEmployees.Recordset.recordcount >=1 then
...

"If SQL > 1 Then"  doesn't work because SQL is a string and don't have any record.

0
 
LVL 1

Expert Comment

by:ramani_gr
ID: 6991059
Rewrite the Function as below and check.

Function DeleteUser()
   dim SQL as String

   SQL = ("Select * from Employees where Admin = true")
   datEmployees.RecordSource = SQL

   If datEmployees.RecordCount > 1 Then
      MsgBox "You can delete the user!"
   Else
      MsgBox "cannot delete last administrator"
   End If
   datEmployees.RecordSource = "Employees"
End Function

Check the Column Admin's data type in Employees Table, and use the same data type in the SQL query

Good luck.
0
 
LVL 49

Expert Comment

by:DanRollins
ID: 7722246
Hi stevenglass,
It appears that you have forgotten this question. I will ask Community Support to close it unless you finalize it within 7 days. I will ask a Community Support Moderator to:

    Accept baltman's comment(s) as an answer.

stevenglass, if you think your question was not answered at all or if you need help, just post a new comment here; Community Support will help you.  DO NOT accept this comment as an answer.

EXPERTS: If you disagree with that recommendation, please post an explanatory comment.
==========
DanRollins -- EE database cleanup volunteer
0
 

Expert Comment

by:SpideyMod
ID: 7779756
per recommendation

SpideyMod
Community Support Moderator @Experts Exchange
0

Featured Post

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Introduction I needed to skip over some file processing within a For...Next loop in some old production code and wished that VB (classic) had a statement that would drop down to the end of the current iteration, bypassing the statements that were c…
There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…

815 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now