Solved

Error code handling incorrect?

Posted on 2008-10-28
1
116 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
1 Comment
 
LVL 32

Accepted Solution

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

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

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
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…

919 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

21 Experts available now in Live!

Get 1:1 Help Now