Home | Forums | Contact | Search | Syndication  
 
 [login] [create account]   Thursday, April 18, 2024 
 
How To Update Controls Across Forms  
Description:  SalesLogix v6 has a great new Forms collection exposed in the Application object. This new collection will solve many problems associated with updating controls across forms. This article will focus on using the Forms collection to do just that.

Category:  Architect How To Articles
Author:  Ryan Farley
Submitted:  1/8/2003
   
Stats: 
Article has been read 18094 times

Rating: - 5.0 out of 5 by 14 users
 

fiogf49gjkf0d
How To Update Controls Across Forms

SalesLogix v6 has a great new Forms collection exposed in the Application object. This new collection will solve many problems associated with updating controls across forms. This article will focus on using the Forms collection to do just that.

The Application.Forms Collection

The SalesLogix Application object exposes a cool new Forms collection. If you have worked with the Forms collection in VB before then this will seem very familiar. Basically, the Forms collection is a collection of all currently loaded Forms (and also Legacy Views) in the Sales Client. What makes this useful is you now have a way to get a reference to another running form and then access essentially anything on that form from your current form - just as if that form was your current form.

Using the Application.Forms Collection

The Forms collection is very easy to use, however there are some problems with its current implementation that do not work correctly as of now. We'll look at what exactly this problem is later, so you don't spend a lot of time trying to use the Forms collection as it is documented in the LAN Developer's Reference in the v6 SDK.

As with any collection, the Forms collection exposes it's count and the items within it. If you want to see a list of all running forms, you could loop through each item in the collection like this:

For i = 0 to Application.Forms.Count - 1
	sForms = sForms & Application.Forms.Item(i).Name & vbCrLf
Next
MsgBox "Total Forms: " & Application.Forms.Count & vbCrLf & vbCrLf & sForms

Easy enough. If you look at the code, we are actually referencing a property of the Form itself in each iteration of the loop. We are accessing it's 'Name' property. Just as easy as it was for us to access the 'Name' property, we can access any property as well as controls on the Form.

Current Problems With Application.Forms

As I mentioned before, the current Application.Forms implementation does have some problems. According to the developer's reference, we should be able to access an item in the Forms collection either by it's index (as we did in the example above) or by the form's plugin name.

For example:

MsgBox Application.Forms("System:Account Detail").Name

However, this does not currently work. Neither does it work to use the form name (as specified in the Name property). No matter what string value you use there, it will return a null reference. You can test this with code similar to the following:

Dim frm

    Set frm = Application.Forms("System:Account Detail")
    If frm Is Nothing Then
        MsgBox "Could not find form reference."
    Else
        MsgBox "You'll never see this message."
    End If    

This does make it a little akward to use syntactically, but it is still completely usable. I'll update this article as soon as I hear back from SalesLogix on this problem.

Using a Form Reference to Update Controls

OK, let's get on with seeing how to use the Form reference for something useful. Let's say we want to update the Account name on the Account Detail Form from another form. What we'll need to do is loop through the Forms collection to find the form we are looking for. This looping is a very minimal hit, since you'll probably only see up to 15 Forms in the collection at any one time. But, what this means, is that the form you're looking for will need to have a unique name. By unique names, I mean that you'll want to change the form's Name property to something meaningful, instead of just leaving it the default value of "Form". The standard Account & Contact Detail Forms do not have unique names. If you want to access them, you'll need to change the Name property of those forms to something meaningful, such as "frmAccountDetail", etc.

So, once we look through the controls and find the Account Detail form, let's use that form reference to update the Account name on that form. The Account name is stored in a text control named "txtAccount". For this example, we'll append the value "Updated" to the name.

Dim frm

	' loop through the forms
	For i = 0 to Application.Forms.Count - 1
		' check if we've found the Account Detail form.
		' make sure you've changed it's Name property.
		If Application.Forms(i).Name = "frmAccountDetail" Then
			' save the reference to this form
			Set frm = Application.Forms(i)
			' now use it to update one of it's controls
			frm.txtAccount.Text = frm.txtAccount.Text & " - UPDATED"
			Exit For
		End If
	Next    

That was easy enough, wasn't it? As you can probably see, it would be very helpful to be able to access the form reference using the plugin name as indicated in the developer's reference. Then you wouldn't have to make sure the forms were named. To make things easier, what I do is wrap this in an easy to use function that I can put in a VBScript and include it whenever I need to get a reference to a Form. Something like this:

Function GetForm(ByVal sFormName)
Dim frm
Dim i

	For i = 0 to Application.Forms.Count - 1
		If Application.Forms(i).Name = sFormName Then
			Set frm = Application.Forms(i)
			Exit For
		End If
	Next
	Set GetForm = frm
End Function    

Now to use it, all you need to do is include the script and do something like this.


Dim frm

Set frm = GetForm("frmAccountDetail")
frm.txtAccount.Text = "This is my new account name"    


Wrapping it Up

Using the Forms collection can be a powerful way to make your SalesLogix forms appear even more as a "built-in" part of the SalesLogix application. Making your forms "talk" to each other will give you even more flexibility as a SalesLogix developer. Learn it, use it, love it.

Until next time, happy coding.
-Ryan
 

About the Author

  Ryan Farley
(SalesLogix Business Partner)
Customer FX Corporation

fiogf49gjkf0d

Ryan Farley is the Director of Development for Customer FX and creator of slxdeveloper.com. He's been blogging regularly about SalesLogix since 2001 and believes in sharing with the community. He loves C#, Javascript, Python, web development, open source, and Linux. He also loves his hobby as an amateur filmmaker.

View Ryan's SalesLogix Mobile Seveloper Series
View Ryan's SalesLogix SData Developer Series
View Ryan's Git for the SalesLogix Developer series



View online profile for Ryan Farley
 

[ back to top] [ send to a friend]  

Rate This Article you must log-in to rate articles. [login here] 
 
Please log in to rate article.
 

Comments & Discussion you must log-in to add comments. [login here] 
 
Author Article Comments and Discussion
Kris Halsrud
 

Great explanation of this
Posted: 1/9/2003 11:50:54 AM
fiogf49gjkf0d
Thanks for this article Ryan, great info for being able to integrate views/ wizards together with other saleslogix screens.
 
Timmus Agersea



You should be able to access forms via their name
Posted: 9/9/2003 4:57:10 PM
fiogf49gjkf0d
You no longer need to loop through the collection to find your form. You can access it as Ryan has outlined, via the name:
Application.Forms("System:Account Detail").txtAccount.Text = "New Account Name"
I apologize that I dont know what version it was fixed, but it does work on the current version 6.1.0.1060.

 
Ryan Farley

slxdeveloper.com Site Administrator
slxdeveloper.com Forum Top 10 Poster!

Re: You should be able to access forms via their name...
Posted: 10/6/2003 1:03:59 AM
fiogf49gjkf0d
Tim,

I believe that was fixed in v6.1. When this article was written that way did not work (as mentioned in the article). But good point, I should update the article to mention that this is now possible. Thanks.

-Ryan
 
Micah Huerta
 

Re: How To Update Controls Across Forms
Posted: 9/8/2004 4:00:16 PM
fiogf49gjkf0d
Is there anyway to dynamicly determine the pluginID of the current form? I'd like to display the Plugin version on the form, to verify that users have the correct version.

Thanks!,
Micah
 
vijayar
 

How To Update Controls Across Forms
Posted: 7/18/2007 8:16:53 AM
fiogf49gjkf0d
I have a problem with updating controls and in my case when i select a row in datagrid(Generated dynamically),corresponding row values needs to be binded to controls in another form.But i am not able to get it.But it is working fine with static datagrid.can u suggest me how to overcome the problem of binding dynamic datagrid values in one form to controls in another form.i have used the following code.

Dim frm
set frm= GetForm("frmExpenseTab")
frm.txtCity.txt="Chennai"
 
Chris Fleetwood
 

Re: How To Update Controls Across Forms
Posted: 2/3/2010 1:56:26 PM
fiogf49gjkf0d
Does the Application.Forms object allow the external firing of a script, such as in the following:

set chkForm = application.Forms("GK Example Form")
chkForm.RefreshGrids()

(where RefreshGrids is a script defined on the "GK Example Form" plugin)

 
Ryan Farley

slxdeveloper.com Site Administrator
slxdeveloper.com Forum Top 10 Poster!

Re: How To Update Controls Across Forms
Posted: 2/3/2010 2:08:39 PM
fiogf49gjkf0d
Chris,

Yes. The Form has a "Script" object that gives you access to these.

Dim frm

Set frm = Application.Forms("System:My Form")
frm.Script.RefreshGrids()

Make sense?
 
Chris Fleetwood
 

Re: How To Update Controls Across Forms
Posted: 2/3/2010 2:32:33 PM
fiogf49gjkf0d
Hey Ryan,

Yes --- that does make sense. And it worked!

You just saved me an hour's worth of "hit and miss" troubleshooting. You are the man! Thanks!

Regards,

Chris
 
Matthew Rose



Re: How To Update Controls Across Forms
Posted: 2/5/2010 3:32:08 AM
fiogf49gjkf0d
This article just saved me another afternoon of heartache! Many thanks guys! :)
 
 

       Visit the slxdeveloper.com Community Forums!
Not finding the information you need here? Try the forums! Get help from others in the community, share your expertise, get what you need from the slxdeveloper.com community. Go to the forums...
 



 slxdeveloper.com is brought to you courtesy of Ryan Farley & Customer FX Corporation.
 This site, and all contents herein, are Copyright © 2024 Customer FX Corporation. The information and opinions expressed here are not endorsed by Sage Software.

code of conduct | Subscribe to the slxdeveloper.com Latest Article RSS feed
   
 
page cache (param): 4/18/2024 6:52:22 PM