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

x
?
Solved

Error code handling incorrect?

Posted on 2008-10-28
1
Medium Priority
?
121 Views
Last Modified: 2012-05-05
Hello,

What am I doing wrong with this code? The database is created,but I also get the message that the code is not generated.

regards,
Dennis
Function Create_DataBase()
Dim name
Dim ok As Boolean
name = Text3.Text
 
'Update Status window
Text2.Text = Text2.Text & vbCrLf & "Creating Database"
DoEvents
 
Set ado = New ADODB.Connection
' setup connectionstring to master database
ado.Open "Driver={SQL Server Native Client 10.0};Server=SCHUTTENVISTA\SQLEXPRESS;Database=master;Uid=sa;Pwd=d27021973;"
 
'First delete the existing database
On Error GoTo err_handler
 ado.Execute ("DROP DATABASE " & name)
On Error GoTo 0
 
 
 
err_handler:
' DATABASE DOES NOT EXIST so move on to the next statement
On Error Resume Next
'Create New database
On Error GoTo err1_handler
ado.Execute "CREATE DATABASE " & name
MsgBox ("Database Created")
On Error GoTo 0
 
'ado.Close
 
err1_handler:
MsgBox ("Database cannot be created, please check if SQL server is running")
Exit Function
 
End Function

Open in new window

0
Comment
Question by:Schuttend
[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
1 Comment
 
LVL 32

Accepted Solution

by:
Daniel Wilson earned 500 total points
ID: 22824995
At line 31 you need
Exit Function

It's falling through to the error handler routine.
0

Featured Post

Industry Leaders: 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!

Question has a verified solution.

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

Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
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…
Suggested Courses

671 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