Solved

code error

Posted on 2002-05-04
8
168 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
 
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
What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

 
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

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
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…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

762 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

19 Experts available now in Live!

Get 1:1 Help Now