Solved

code error

Posted on 2002-05-04
8
171 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
Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

 
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
Excel VBA combine two working workbooks 8 60
Microsoft Access combo box help 2 49
Recommendation vb6 to vb.net or others 14 175
MsgBox 4 68
The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
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 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…
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…

856 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