Solved

code error

Posted on 2002-05-04
8
172 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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Sending a email via excel using vba 6 109
SLMGR Switches Are Not Working On KMS Host 3 137
Visual Studio 2005 text editor 10 47
Assign a value in Excel V-Basic 3 28
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…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
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…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…

679 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