'This procedure executes Action Query SQL in the SQL Azure master database.
'The Procedure Argument "strData" is used like a password to make this powerful Procedure secure.
'Example usage: Call ExecuteMasterDBSQL(strSQL, "U_n9Yg&E8H5u6\p$Ma+r/J2%yeg")
'Or If ExecuteMasterDBSQL(strSQL, "U_n9Yg&E8H5u6\p$Ma+r/J2%yeg") = False Then
Function ExecuteMasterDBSQL(strSQL As String, strData As String) As Boolean
On Error GoTo ErrHandle

    Dim db As DAO.Database
    Dim qdf As DAO.QueryDef

    ExecuteMasterDBSQL = False 'Default Value

    'This line ensures the code only runs if the "Password" Argument "strData" is correct.
    If strData = "U_n9Yg&E8H5u6\p$Ma+r/J2%yeg" Then
        Set db = CurrentDb

        'Create a temporary unnamed Pass-through QueryDef. This is a
        'practice recommended in the Microsoft Developer Reference.
        'The order of each line of code must not be changed or the code will fail.
        Set qdf = db.CreateQueryDef("")
        'Use a function to get the SQL Azure Connection string to the master database
        qdf.Connect = obfuscatedFunctionName
        'Set the QueryDef's SQL as the strSQL passed in to the procedure
        qdf.SQL = strSQL
        'ReturnsRecords must be set to False if the SQL does not return records
        qdf.ReturnsRecords = False
        'Execute the Pass-through query
        qdf.Execute dbFailOnError

        'If no errors were raised the query was successfully executed
        ExecuteMasterDBSQL = True
    End If

    'Cleanup for security and to release memory
    On Error Resume Next
    Set qdf = Nothing
    Set db = Nothing
    Exit Function

    MsgBox "Error " & Err.Number & vbCrLf & Err.Description _
    & vbCrLf & "In Procedure ExecuteMasterDBSQL"
    Resume ExitHere

End Function

'The cmdCreateLogin_Click Sub 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() 'Prepare a Variable to hold the SQL statement Dim strSQL As String 'Build the SQL statement strSQL = "CREATE LOGIN " & Me.txtLoginName & " WITH password = '" & Me.txtPassword & "'" 'Verify both a Login Name and a Password has been entered. If Len(Me.txtLoginName & vbNullString) = 0 Then 'A Login Name has not been entered. MsgBox "Please enter a value in the Login Name text box.", vbCritical Else 'We have a Login Name, verify a Password has been entered. If Len(Me.txtPassword & vbNullString) = 0 Then 'A Password has not been entered. MsgBox "Please enter a value in the Password text box.", vbCritical Else 'We have a Login Name and a Password. 'Create the Login by calling the ExecuteMasterDBSQL Function. If ExecuteMasterDBSQL(strSQL, "U_n9Yg&E8H5u6\p$Ma+r/J2%yeg") = 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