Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 22
Default Passing Array of User Defined Type to Form

Worked like a charm, Rick. Many thanks for your help.

"Rick Rothstein (MVP - VB)" wrote:

I see two things that I think are causing you problems. One, if pmhc is
declared in the module, it should use Public, not Dim to declare it. Two,
take the parentheses off of the do_admin call. The correct syntax is either
this...

do_admin pmhc()

or this...

Call do_admin(pmhc())

You should **only** use parentheses where **required** by syntax or in
forcing precedence in an expression evaluation. The problem is that when you
use non-syntax parentheses, VB assumes an expression is being evaluated. You
can get away with this for single, simple variable arguments in
function/subroutine calls because VB's evaluation of them as an expression
is simply themselves. But complex things, like Type arrays, multiple
arguments, and such are another story and VB doesn't know what to do with
them. You might be able to get away with complex things like an Object, such
as a control name, but that is because the Object has a default property and
VB will use that as the evaluation of the Object and, if the data type
matches what the function or subroutine is expecting, will pass it with out
raising an objection. The best rule to follow, though, is to use parentheses
only when required and not to "pretty things up".

Rick



"dunnerca" wrote in message
...
Thanks Rick. Here's the code you asked for. Thanks. Sorry for the delay
in
answering but I went to bed after posting.

a) Setting up the UD type
Public Type team
teamname As String
code As String
manager As String
m_email As String
End Type

Dim pmhc(1 To 12) As team

b) Code To Fill The Array (takes information from a worksheet;

Sub fill_array(pmhc() As team)

' In the worksheet called "Teams", the data is as follows:
' Column A - numbers 1 to 12
' Column B - Name of team
' Column C - Team manager
' Column D - Team code
' Column E - Manager's email

For x = 1 To 12
' Populate the team name fields;

tmp_range = "b" & Trim(Str(x))
pmhc(x).teamname = Worksheets("teams").Range(tmp_range).Value
Next
For x = 1 To 12
' Populate the team code fields;
tmp_range = "d" & Trim(Str(x))
pmhc(x).code = Worksheets("teams").Range(tmp_range).Value
Next
For x = 1 To 12
' Populate the team manager fields;
tmp_range = "c" & Trim(Str(x))
pmhc(x).manager = Worksheets("teams").Range(tmp_range).Value
Next
For x = 1 To 12
' Populate the email fields;
tmp_range = "e" & Trim(Str(x))
pmhc(x).m_email = Worksheets("teams").Range(tmp_range).Value
Next

End Sub

c) The click event code from the user form:

Sub cmd_Admin_Click()
frm_main.Hide
do_admin (pmhc())
End Sub



Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Passing an array in a user defined function Peter M Excel Programming 5 June 27th 08 10:45 PM
Type Mismatch: array or user defined type expected ExcelMonkey Excel Programming 4 July 6th 06 03:40 PM
Help: Compile error: type mismatch: array or user defined type expected lvcha.gouqizi Excel Programming 1 October 31st 05 08:20 PM
Passing User Defined Type Array to Listbox PC[_4_] Excel Programming 2 June 1st 05 02:44 AM
Passing an Array of User-Defined Type to an Argument of a Function Tushar Mehta[_6_] Excel Programming 0 August 17th 03 06:43 PM


All times are GMT +1. The time now is 06:35 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"