Function ExecuteMasterDBSQL(strSQL As String) As Boolean
On Error GoTo ErrHandle
Dim db As DAO.Database
Dim qdf As DAO.QueryDef
ExecuteMasterDBSQL = False
Set db = CurrentDb
Set qdf = db.CreateQueryDef("")
qdf.Connect = obfuscatedFunctionName
qdf.SQL = strSQL
qdf.ReturnsRecords = False
qdf.Execute dbFailOnError
ExecuteMasterDBSQL = True
ExitHere:
On Error Resume Next
Set qdf = Nothing
Set db = Nothing
Exit Function
ErrHandle:
MsgBox "Error " & Err.Number & vbCrLf & Err.Description _
& vbCrLf & "In procedure ExecuteMasterDBSQL"
Resume ExitHere
End Function
The Sub below is to be used for a command button in a form. It verifies that a Login Name and Password has been entered in text boxes and then it calls the ExecuteMasterDBSQL Function above to create a Login in a SQL Azure master database.
Private Sub cmdCreateLogin_Click()
Dim strSQL As String
strSQL = "CREATE LOGIN " & Me.txtLoginName & " WITH password = '" & Me.txtPassword & "'"
If Len(Me.txtLoginName & vbNullString) = 0 Then
MsgBox "Please enter a value in the Login Name text box.", vbCritical
Else
If Len(Me.txtPassword & vbNullString) = 0 Then
MsgBox "Please enter a value in the Password text box.", vbCritical
Else
If ExecuteMasterDBSQL(strSQL) = False Then
MsgBox "The Login failed to be created.", vbCritical
Else
MsgBox "The Login was successfully created.", vbInformation
End If
End If
End If
End Sub