Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

code error

Posted on 2002-05-04
8
Medium Priority
?
177 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
8 Comments
 
LVL 1

Accepted Solution

by:
baltman earned 200 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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
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

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

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

Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
Suggested Courses

721 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