469,073 Members | 1,808 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,073 developers. It's quick & easy.

Form Name As Sub Parameter

Breezwell
Hello everyone,

This seems like a simple thing to do, however no matter what I try I cannot manage to pass a form name to a function in order to open that form. The name of the form is DisplayUI_CoreSearch_UniqueGroupCode_Count. The function is stored in a module called modUniqueCounts.

I keep getting a ByRef argument type mismatch error.
Procedure
************
Expand|Select|Wrap|Line Numbers
  1. Public Sub UniqueCountFormDisplay(FName As Form)
  2.  
  3.     DoCmd.OpenForm FName, acNormal
  4.  
  5. End Sub
Event That Calls the Function
**********************************
Expand|Select|Wrap|Line Numbers
  1. Private Sub txtUniqueFlavorCount_Selling_Click()
  2.  
  3. Call UniqueCountFormDisplay(DisplayUI_CoreSearch_UniqueGroupCode_Count)
  4.  
  5. End Sub
Thanks for any insight.
Jun 6 '09 #1
4 1987
missinglinq
3,532 Expert 2GB
Change these two lines as indicated:

Expand|Select|Wrap|Line Numbers
  1. Call UniqueCountFormDisplay("DisplayUI_CoreSearch_Unique GroupCode_Count")
Notice the quotes around the form name.

Expand|Select|Wrap|Line Numbers
  1. Public Sub UniqueCountFormDisplay(FName As String)
Linq ;0)>
Jun 6 '09 #2
NeoPa
32,154 Expert Mod 16PB
Linq's solution is the more sensible, but in case you need to know how to pass forms (rather than simply their names) to procedures, here is what you need :
Procedure
Expand|Select|Wrap|Line Numbers
  1. Public Sub UniqueCountFormDisplay(ByRef FName As Form)
  2.  
  3.     DoCmd.OpenForm FName.Name, acNormal
  4.  
  5. End Sub
Event That Calls the Function
Expand|Select|Wrap|Line Numbers
  1. Private Sub txtUniqueFlavorCount_Selling_Click()
  2.  
  3.     Call UniqueCountFormDisplay(Form_DisplayUI_CoreSearch_UniqueGroupCode_Count)
  4.     'Or, if you know the form is open already
  5.     Call UniqueCountFormDisplay(Forms!DisplayUI_CoreSearch_UniqueGroupCode_Count)
  6.  
  7. End Sub
Jun 6 '09 #3
Thanks for the feedback guys.

I utilized passing the form name as a string, however both solutions have taught me something new.

Again, thanks for the great help!
Jun 10 '09 #4
NeoPa
32,154 Expert Mod 16PB
You'r very welcome :)

I think I'd have used Linq's solution in your position too ;)
Jun 10 '09 #5

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

reply views Thread by Willoughby Bridge | last post: by
10 posts views Thread by Gregory A Greenman | last post: by
reply views Thread by Frank 'Olorin' Rizzi | last post: by
21 posts views Thread by Just Me | last post: by
8 posts views Thread by Vivek | last post: by
27 posts views Thread by Chris | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by zhoujie | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.