Lauriedomini
New Member
- Joined
- Apr 19, 2017
- Messages
- 1
Hello,
I've been running into errors in VBA in terms of inserting a frm. I get the error "Out of Memory." And the log says this: Line 8: Property OleObjectBlob in frmLogin had an invalid file reference. I've read through other posts in which this was resolved by changing the name of the frm to match the VBA code or removing extraneous "$" symbols in the VBA code. But this hasn't worked for me.
Can you tell me how I can fix my issue? Specifically this is what I'm doing...
Adding the below code to "ThisWorkbook":
Then right clicking on "ThisWorkbook" and inserting a frm that I saved to the desktop called "frmLogin.frm"
The code in the workbook.
Laurie
I've been running into errors in VBA in terms of inserting a frm. I get the error "Out of Memory." And the log says this: Line 8: Property OleObjectBlob in frmLogin had an invalid file reference. I've read through other posts in which this was resolved by changing the name of the frm to match the VBA code or removing extraneous "$" symbols in the VBA code. But this hasn't worked for me.
Can you tell me how I can fix my issue? Specifically this is what I'm doing...
Adding the below code to "ThisWorkbook":
Code:
Option Explicit
Private Sub workbook_open()
frmLogin.Show
End Sub
Then right clicking on "ThisWorkbook" and inserting a frm that I saved to the desktop called "frmLogin.frm"
The code in the workbook.
Code:
VERSION 5.00
Begin {XXXXXXX} frmLogin
Caption = "XXXXXXXXX - Secure Login"
ClientHeight = 2625
ClientLeft = 45
ClientTop = 375
ClientWidth = 5865
OleObjectBlob = "frmLogin.frx":0000
StartUpPosition = 1 'CenterOwner
End
Attribute VB_Name = "frmLogin"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Option Explicit
Private Sub cmdCancel_Click()
frmLogin.Hide
Unload frmLogin
Exit Sub
End Sub
Private Sub cmdOk_Click()
Dim wc As WorkbookConnection
Dim oc As OLEDBConnection
For Each wc In ActiveWorkbook.Connections
If wc.Type = xlConnectionTypeOLEDB Then
If wc.OLEDBConnection.OLAP Then
If GetConnectionParameterValue(wc.OLEDBConnection.Connection, "User ID") <> frmLogin.txtUid Then
wc.OLEDBConnection.Connection = SetConnectionParameterValue(wc.OLEDBConnection.Connection, "User ID", frmLogin.txtUid)
End If
wc.OLEDBConnection.Connection = SetConnectionParameterValue(wc.OLEDBConnection.Connection, "Password", frmLogin.txtPwd)
wc.OLEDBConnection.MakeConnection
wc.OLEDBConnection.SavePassword = False
End If
End If
Next
frmLogin.Hide
Unload frmLogin
End Sub
Private Sub UserForm_Activate()
Dim wc As WorkbookConnection
Dim oc As OLEDBConnection
For Each wc In ActiveWorkbook.Connections
If wc.Type = xlConnectionTypeOLEDB Then
If wc.OLEDBConnection.OLAP Then
Me.txtUid = GetConnectionParameterValue(wc.OLEDBConnection.Connection, "User ID")
Exit For
End If
End If
Next
frmLogin.txtPwd.SetFocus
End Sub
Private Function GetConnectionParameterValue(Connection As String, ParameterName As String) As String
Dim StartPos As Integer
Dim EndPos As Integer
Dim ParameterValue As String
Dim Parameter As String
StartPos = InStr(1, Connection, ParameterName, vbTextCompare)
If StartPos > 0 Then
EndPos = InStr(StartPos, Connection, ";", vbTextCompare)
If EndPos = 0 Then
Parameter = Mid(Connection, StartPos)
Else
Parameter = Mid(Connection, StartPos, EndPos - StartPos)
End If
Dim ValueStartPos As Integer
ValueStartPos = InStr(1, Parameter, "=")
If ValueStartPos = 0 Then
GetConnectionParameterValue = ""
Else
GetConnectionParameterValue = Mid(Parameter, ValueStartPos + 1, Len(Parameter) - ValueStartPos)
End If
End If
End Function
Private Function SetConnectionParameterValue(Connection As String, ParameterName As String, ParameterValue As String) As String
Dim StartPos As Integer
Dim EndPos As Integer
Dim Parameter As String
StartPos = InStr(1, Connection, ParameterName, vbTextCompare)
If StartPos > 0 Then
EndPos = InStr(StartPos, Connection, ";", vbTextCompare)
If EndPos = 0 Then
Parameter = Mid(Connection, StartPos)
Else
Parameter = Mid(Connection, StartPos, EndPos - StartPos)
End If
SetConnectionParameterValue = Replace(Connection, Parameter, ParameterName & "=" & ParameterValue, 1, -1, vbTextCompare)
Else
Dim Separator As String
Connection = Trim(Connection)
If Mid(Connection, Len(Connection), 1) = ";" Then
Separator = ""
Else
Separator = ";"
End If
SetConnectionParameterValue = Connection & Separator & ParameterName & "=" & ParameterValue & ";"
End If
End Function
Laurie