How can I find out the form's index number? I found this function (see below) on google after a second day of searching, but I'm not sure how to make it work with multiple instances of the same form. Because if I pass the forms name then I always keep getting the same index.
(Please don't refer me to searching on "multiple instances" because I read every single link here, on google msg boards and yahoo and just can't put it all together; pls see below)
My form has a button that initiates the code:
function:
I found this solution on multiple instances and collections: http://allenbrowne.com/ser-35.html and it works well initiating multiple instances, but it doesn't explain the next step which is refering to a perticular instance.
After another day of searching I found this (http://groups.google.com/group/micr...r+instance+form&rnum=1&hl=en#5d579e492d3689ea) with the code:
but I'm quite new with vba and can't seem to put it all together to be able to refer to a particular instance or at least simply find out the index number of an instance that executes the code. I would simply like to be able to click a button on an instance of the MainForm and have a msgBox popop with the Index number of that particular instance. (From there I can menage myself)
Please, please help, this is the 48hr without food
(Please don't refer me to searching on "multiple instances" because I read every single link here, on google msg boards and yahoo and just can't put it all together; pls see below)
My form has a button that initiates the code:
Code:
i = fGetOrdinal("myformName")
MsgBox i
function:
Code:
Function fGetOrdinal(strForm As String) As Integer
Dim strMsg As String
Dim i As Integer
On Local Error GoTo fGetOrdinal_Err
fGetOrdinal = -1
For i = 0 To Forms.Count - 1
If Forms(i).Name = strForm Then
fGetOrdinal = i
Exit For
End If
Next
fGetOrdinal_End:
Exit Function
fGetOrdinal_Err:
fGetOrdinal = -1
strMsg = "Error Information..." & vbCrLf & vbCrLf
strMsg = strMsg & "Function: fGetOrdinal" & vbCrLf
strMsg = strMsg & "Description: " & Err.Description & vbCrLf
strMsg = strMsg & "Error #: " & Format$(Err.Number) & vbCrLf
MsgBox strMsg, vbInformation, "fGetOrdinal"
Resume fGetOrdinal_End
End Function
I found this solution on multiple instances and collections: http://allenbrowne.com/ser-35.html and it works well initiating multiple instances, but it doesn't explain the next step which is refering to a perticular instance.
After another day of searching I found this (http://groups.google.com/group/micr...r+instance+form&rnum=1&hl=en#5d579e492d3689ea) with the code:
Code:
For lng = 0 To Forms.Count - 1
If Forms(lng).hWnd = 9999 Then
MsgBox "The instance is Forms(" & lng & ")"
End If
Exit For
Next
Please, please help, this is the 48hr without food
