borderAndreaVB free resources for Visual Basic developersborder

borderAndreaVB Visual Basic and VB.NET source code resources - Copyright © 1999-2007 Andrea Tincaniborder

AndreaVB | Forum | News | Downloads | Register | Help | Member List | Statistics | Search | PM | Profile

Print This Topic
Previous Topic (Validating con.execute statement)Next Topic (Compressing Access DB) New Topic New Poll Post Reply
AndreaVB Forum : Database : Public Function call
Poster Message
Cpen
Level: Trainee

Registered: 06-03-2006
Posts: 1

icon Public Function call

Hello everyone! Thanks in advanced for the help.


Ok im very new to programing so bare with me:

This is inregards to MS Access DB

What Im trying to do is have a public function that I can call from one of the forms i made. With the function I want it to lock all fields and unlock fields that isnt the problem. The problem im having is im trying to change the forms name dynamically to adjust to the different forms i will be having to unlock/lock.

Here is the function:

Public Function Lockit()

dim cForm as form

Set cForm = Forms!frmTform (This is for one form only but I want it to change dynamically to fit other forms without having to cut and paste this code over and over again)
    cForm.cmd1.Enabled = True
    cForm.cmd1.Locked = False  
etc etc


So if I have a different form named Forms!frmB i want it to be insterted in the set cForm and thus changing all the cForm's to the new Forms!frmB

Hope this make sense!


[Edited by Cpen on 06-03-2006 at 04:25 PM GMT]

06-03-2006 at 04:25 PM
View Profile Send Email to User Show All Posts | Quote Reply
Goran
Level: Moderator

Registered: 16-05-2002
Posts: 1681
icon Re: Public Function call

There is a Forms collection which contain all opened forms. All you need to do is loop through it and find a form by name that you want to access. In addition, public sub will receive a form's bane as a parameter.

Public Function Lockit(frmName as string) as boolean

dim cForm as form

    for each cform in forms
        if cform.name=frmname then
            cForm.cmd1.Enabled = True
            cForm.cmd1.Locked = False
            lockit=true
        endif
    next cform
end function


____________________________
If you find the answer helpful, please mark this topic as solved.

06-03-2006 at 09:49 PM
View Profile Send Email to User Show All Posts | Quote Reply
AndreaVB Forum : Database : Public Function call
Previous Topic (Validating con.execute statement)Next Topic (Compressing Access DB) New Topic New Poll Post Reply
Surf To:


Not Logged In? Username: Password: Lost your password?
Partners: Download Actual Software | Free Software Download
borderAndreaVB free resources for Visual Basic developersborder

borderAndreaVB Visual Basic and VB.NET source code resources - Copyright © 1999-2007 Andrea Tincaniborder