Results 1 to 8 of 8
  1. #1
    zx3 is offline Advanced Beginner
    Windows 7 64bit Access 2007
    Join Date
    Aug 2011
    Posts
    47

    Exclamation How to manipulate another form which is using class module


    Hi all,

    I have an Access file with 2 forms, what i want to do is...

    I try to physically clicking inside one of the generated result textbox(Alpha column), and vba on Form1 will

    i. click a button on Form2, and the finally result is showed on textbox in Form2. Or

    ii. choose an option in Combobox on Form2, and the finally result is showed on textbox in Form2.

    however Form2 is related to a class module.

    If i only interact with Form2, i click a button on Form2 or choose an option in Combobox on Form2, I want the results same as above two,

    Doing it without the class module related to Form2 is easy to me, but with the class module i really need you guys to help.

    Please tell me how do i achieve the above two. Here is the file Database5.zip

  2. #2
    Gicu's Avatar
    Gicu is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Jul 2015
    Location
    Kelowna, BC, Canada
    Posts
    4,114
    Is this what you mean:
    Code:
    'form1
    Private Sub t2_Click()
        For Each obj In Application.CurrentProject.AllForms 'close all forms that opened
            If obj.IsLoaded = False And obj.Name = "Form2" Then
                DoCmd.OpenForm "Form2", acNormal
                'flg = 1 'flag to show form2 need to be opened
                Exit For
            End If
        Next
        'Forms("Form2").Controls("cd").ListIndex = a + 1
        
        Call Form_Form2.Combo1_Change 'Vlad March3/2020 -in form2 I changed the sub from Private to Public
        
    End Sub
    'form2
    Public Sub Combo1_Change() 'if value of combo1 changed
        Set db = CurrentDb
        Set cdb = db.OpenRecordset("SELECT * FROM Table1 WHERE num = '" & Combo1.Value & "'", dbOpenSnapshot)
        Me.t1.Value = cdb.alpha
    End Sub
    Cheers,
    Vlad Cucinschi
    MS Access Developer
    http://forestbyte.com/

  3. #3
    zx3 is offline Advanced Beginner
    Windows 7 64bit Access 2007
    Join Date
    Aug 2011
    Posts
    47
    Thanks Gicu for your reply,

    Unfortunately, no

    it is all done by vba, like the following, but i can't get the lines to click the button or chose the option from the combobox in Form2

    DoCmd.OpenForm "Form2", acNormal 'in form1, something like this

    Forms("Form2").Controls("combo1").ListIndex = a + 1 'in form1, something like this


    Code:
    Private Sub t2_Click() 'this Sub is in Form1
    'the above 2 lines should be here somewhere
    End Sub
    Obviously the above do not work because the buttons on Form2 are related to the class module

  4. #4
    Gicu's Avatar
    Gicu is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Jul 2015
    Location
    Kelowna, BC, Canada
    Posts
    4,114
    See this one please.
    Attached Files Attached Files
    Vlad Cucinschi
    MS Access Developer
    http://forestbyte.com/

  5. #5
    zx3 is offline Advanced Beginner
    Windows 7 64bit Access 2007
    Join Date
    Aug 2011
    Posts
    47
    Thanks Gicu for your reply, I do not get the result i want from the code line you added. May be this one is a bit hard to tell, let me explain it with more details, and please be patient with me 1. first go to form1 and chose the option from the combobox, say it is a 4, from 1-8, then there will be 4 pairs of alpha and num appear below 2. on form1 with the 4 pairs appear, say click G, that is t2 (textbox), it will run the vba code Private Sub t2_Click() 3. inside Private Sub t2_Click() of form1, there should be some code lines to add, say Forms("Form2").Controls("combo1").ListIndex = a to select the option in combo1 of form2, which in turn put alpha in t1 of form2 or if i want use code to click the button on form2, it could be 3. inside Private Sub t2_Click() of form1, there should be some code lines to add, say Forms("Form2").cb6_click to click the G button of form2, which in turn put alpha in t1 of form2 what i do not know is what code to put in Private Sub t2_Click() , as buttons in form2 are related to class module By clicking buttons on form2 or choose an option in combo1 on form2 will generate the same result, but i want to get result from t1 of form2 by clicking textbox t2(one of the generated row) in from1. Hope you guys know what i want this time. ;(
    Last edited by zx3; 03-10-2020 at 01:17 PM. Reason: too hard to read

  6. #6
    zx3 is offline Advanced Beginner
    Windows 7 64bit Access 2007
    Join Date
    Aug 2011
    Posts
    47
    sorry for last post, it suddenly lost formatting and lump the paragraphs into a block. ;(

  7. #7
    Gicu's Avatar
    Gicu is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Jul 2015
    Location
    Kelowna, BC, Canada
    Posts
    4,114
    Here you go, I added three methods to do it, hopefully I got your intent now.
    Cheers,
    Vlad
    Attached Files Attached Files
    Vlad Cucinschi
    MS Access Developer
    http://forestbyte.com/

  8. #8
    zx3 is offline Advanced Beginner
    Windows 7 64bit Access 2007
    Join Date
    Aug 2011
    Posts
    47

    Wink

    Thanks Gicu, you have been a great help to my project, i understand what you tried to do, and that's what i need.

    I know there is more to add to the code, and i am working on it.

    Great work! and thanks again to Gicu and all other guys that are interested in this post.

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 9
    Last Post: 09-29-2017, 02:04 PM
  2. Replies: 6
    Last Post: 01-13-2015, 04:54 PM
  3. Initialization Module/Class
    By swalsh84 in forum Modules
    Replies: 1
    Last Post: 12-13-2014, 12:25 PM
  4. Replies: 2
    Last Post: 01-07-2013, 07:24 AM
  5. class module vs regular module
    By Madmax in forum Modules
    Replies: 1
    Last Post: 05-01-2012, 03:44 PM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums