Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Microsoft Office > Access and Access VBA > Access VBA
|
Access VBA Discuss using VBA for Access programming.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Access VBA section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old December 9th, 2007, 07:09 PM
Authorized User
 
Join Date: Nov 2006
Posts: 21
Thanks: 0
Thanked 0 Times in 0 Posts
Default Help needed in figuring out some Frame Code

I doing this as an experiment (Microsoft Access 2003) and need some help to finalize as it bombs out and I don't know what I have done wrong.

The ultimate goal is so that someone using this would be able to have a visual representation of what process they are currently doing. Or where they are at on the form. For the most part my end users are minimizing access to run other apps as they are multitasking. When they come back to the form (presently) they forget what they were doing. This causes some buttons to get pressed out of sequence or not at all. So. this is a means in which they would have a color representation of where they left off when they come back to continue the process for the task they are working on.


I have created a form (Frame) with frame wizard.
1. It has a Form_Load event
2. Form_UnLoad event
3. The frame contains 6 toggle buttons, numbered as follows;
a. Name: Toggle39, Caption: Option1
b. Name: Toggle40, Caption: Option2
c. Name: Toggle41, Caption: Option3
d. Name: Toggle42, Caption: Option4
e. Name: Toggle43, Caption: Option5
f. Name: Toggle44, Caption: Option6

4. I also have a label Name: lblTrick, Caption: Option 6, with a back color of Yellow.




Here is the code for Form Load:
Private Sub Form_Load()
'On form load, show all pushbuttons as not selected
    Set rs = New ADODB.Recordset
    With rs
        .Fields.Append "Option", adInteger
        .Open
    End With
    bLoad = True
    Frame36_Click
End Sub
Here is the code for the form_unload:
Private Sub Form_Unload(Cancel As Integer)
    Dim i As Integer
    'If rs.RecordCount <> Frame36.Controls.Count - 1 Then 'Original code
    If rs.RecordCount <> Frame36.Controls.Count Then
        'They have not completed all of the steps
        i = MsgBox("You did not complete all of the steps" & vbCrLf & "are you sure you want to exit?", vbYesNo)
    Else
        MsgBox "you've completed your work"
        DoCmd.Close acForm, "Form1", acSavePrompt
        'You're done, do whatever you need to do to properly close your form
        Exit Sub
    End If
    If i = vbYes Then
        'exit
        DoCmd.Close acForm, "Form1", acSavePrompt
        'MsgBox "Virutal Closing of the form"
    Else
        'bail out
        MsgBox "Keep the form open and finish work"

    End If

End Sub

Here is the code for the Frame:
Private Sub Frame36_Click()
'keeping track of which button has been selected....lets user know if they have previously selected
    With rs

        If Not rs.EOF Then
            .MoveFirst
            .Find "Option = " & Frame36.Value
            If .EOF Then
                .AddNew 0, Frame36.Value
            Else
                MsgBox "you've already done this option"
            End If
        Else
            .AddNew 0, Frame36.Value
        End If

    End With
    ToggleButtChg
    'click events go here
    Select Case Frame36.Value
        Case 1
            MsgBox "Insert Code here for event " & Frame36.Controls(Frame36.Value).Caption
        Case 2
            MsgBox "Insert Code here for event " & Frame36.Controls(Frame36.Value).Caption
        Case 3
            MsgBox "Insert Code here for event " & Frame36.Controls(Frame36.Value).Caption
        Case 4
            MsgBox "Insert Code here for event " & Frame36.Controls(Frame36.Value).Caption
        Case 5
            MsgBox "Insert Code here for event " & Frame36.Controls(Frame36.Value).Caption
        Case 6
            MsgBox "Insert Code here for event " & Frame36.Controls(Frame36.Value).Caption
    End Select

End Sub

Here is the code for the Option6 label: lblTrick

Private Sub ToggleButtChg()
' keeping track of which button was selected...move the text box over that button to show it has been selected
'This is a visual que for the user so they can visually see where they are in a multi-step process
   Dim iCt As Integer
    With Frame36
    If bLoad Then
        lblTrick.Visible = False
        For iCt = 1 To .Controls.Count - 1
            .Controls.Item(iCt).Visible = True
        Next iCt
        bLoad = False
        Frame36.Value = Frame36.DefaultValue
    Else
    lblTrick.Visible = True
        lblTrick.Left = .Controls(.Value).Left
        lblTrick.Top = .Controls(.Value).Top
        lblTrick.Height = .Controls(.Value).Height
        lblTrick.Width = .Controls(.Value).Width
        lblTrick.Caption = .Controls(.Value).Caption

        For iCt = 1 To .Controls.Count - 1
            If iCt = .Value Then
                .Controls.Item(.Value).Visible = False
            Else
                .Controls.Item(iCt).Visible = True
            End If
        Next iCt
    End If
    End With
End Sub


Thanks in Advance,

John



 
Old December 10th, 2007, 08:58 AM
Friend of Wrox
 
Join Date: Mar 2004
Posts: 3,069
Thanks: 0
Thanked 10 Times in 10 Posts
Default

How about something like this:

Private Sub Form_Load()
Me.Toggle0.DefaultValue = 0
Me.Toggle1.DefaultValue = 0
Me.Toggle2.DefaultValue = 0
Me.Toggle3.DefaultValue = 0
Me.Toggle4.DefaultValue = 0
Me.Toggle5.DefaultValue = 0
End Sub

Private Sub Toggle0_Click()
'Do some action like...
MsgBox "Toggle0 clicked."
Me.Toggle1.SetFocus
Me.Toggle0.Enabled = False
End Sub

Private Sub Toggle1_Click()
'Do some action like...
MsgBox "Toggle1 clicked."
Me.Toggle2.SetFocus
Me.Toggle1.Enabled = False
End Sub

etc

This passes the focus to the next toggle button, and then disables the toggle that was just clicked. That was the user can't redo an action, and can see from the toggle states that some action has already occurred.

You could also add a text box, and set the value with code like:

Private Sub Form_Load()
Me.Toggle0.DefaultValue = 0
Me.Toggle1.DefaultValue = 0
Me.Toggle2.DefaultValue = 0
Me.Toggle3.DefaultValue = 0
Me.Toggle4.DefaultValue = 0
Me.Toggle5.DefaultValue = 0
Me.Text0 = "No Actions Processed"

End Sub

Private Sub Toggle0_Click()
MsgBox "Toggle0 clicked."
Me.Toggle1.SetFocus
Me.Toggle0.Enabled = False
Me.Text0 = "Toggle Action 0 Processed"
End Sub

Private Sub Toggle1_Click()
MsgBox "Toggle1 clicked."
Me.Toggle2.SetFocus
Me.Toggle1.Enabled = False
Me.Text0 = "Toggle Action 1 Processed"
End Sub

etc.

This will get the functionality that you want.
You can add another button to reset the toggles if you want.

Did that help?


mmcdonal

Look it up at: http://wrox.books24x7.com
 
Old December 28th, 2007, 03:10 PM
Authorized User
 
Join Date: Nov 2006
Posts: 21
Thanks: 0
Thanked 0 Times in 0 Posts
Default

For some reason, this isn't working. I get the following error:

Run-time error '2455'

You entered an expression that has an invalid reference to the property DefaulyValue.

When you select the Debug pushbutton, it highlights the Me.Toggle0.DefaultValue = 0

So, what am I doing wrong.

I basically cut and pasted the code in.

Tks,

John


 
Old December 28th, 2007, 03:43 PM
Friend of Wrox
 
Join Date: Mar 2004
Posts: 3,069
Thanks: 0
Thanked 10 Times in 10 Posts
Default

Me.Toggle0.Value, not Default Value. Here is what I created on a form and really went nuts:

Private Sub Form_Load()
Me.Toggle0.Value = 0
Me.Toggle0.Caption = "Me First"
Me.Toggle1.Value = 0
Me.Toggle1.Enabled = False
Me.Toggle2.Value = 0
Me.Toggle2.Enabled = False
Me.Toggle3.Value = 0
Me.Toggle3.Enabled = False
Me.Toggle4.Value = 0
Me.Toggle4.Enabled = False

Me.Text5 = "No Actions Processed"

End Sub

Private Sub Toggle0_Click()
Me.Text5 = "Toggle 0 Clicked"
Me.Toggle1.Enabled = True
Me.Toggle1.SetFocus
Me.Toggle1.Caption = "Me Next"
Me.Toggle0.Caption = ""
Me.Toggle0.Enabled = False

End Sub

Private Sub Toggle1_Click()
Me.Text5 = "Toggle 1 Clicked"
Me.Toggle2.Enabled = True
Me.Toggle2.SetFocus
Me.Toggle2.Caption = "Me Next"
Me.Toggle1.Caption = ""
Me.Toggle1.Enabled = False
End Sub

Private Sub Toggle2_Click()
Me.Text5 = "Toggle 2 Clicked"
Me.Toggle3.Enabled = True
Me.Toggle3.SetFocus
Me.Toggle3.Caption = "Me Next"
Me.Toggle2.Caption = ""
Me.Toggle2.Enabled = False
End Sub

Private Sub Toggle3_Click()
Me.Text5 = "Toggle 3 Clicked"
Me.Toggle4.Enabled = True
Me.Toggle4.SetFocus
Me.Toggle4.Caption = "Me Next"
Me.Toggle3.Caption = ""
Me.Toggle3.Enabled = False
End Sub

Private Sub Toggle4_Click()
Me.Text5 = "Toggle 4 Clicked - All Actions Completed"
Me.Command7.SetFocus
Me.Toggle4.Caption = ""
Me.Toggle4.Enabled = False
End Sub

Private Sub Command7_Click()
Me.Toggle0.Value = 0
Me.Toggle0.Enabled = True
Me.Toggle0.Caption = "Me First"

Me.Toggle1.Value = 0
Me.Toggle1.Enabled = False

Me.Toggle2.Value = 0
Me.Toggle2.Enabled = False

Me.Toggle3.Value = 0
Me.Toggle3.Enabled = False

Me.Toggle4.Value = 0
Me.Toggle4.Enabled = False

Me.Text5 = "No Actions Processed"
End Sub

Did that help?


mmcdonal

Look it up at: http://wrox.books24x7.com
 
Old December 28th, 2007, 04:09 PM
Authorized User
 
Join Date: Nov 2006
Posts: 21
Thanks: 0
Thanked 0 Times in 0 Posts
Default

What did you call the form you made?

I'm still getting an error;

Run-time error 2448

You can't assign a value to this object
Hit debug;


Private Sub Form_Load()
Me.Toggle0.Value = 0


john

 
Old December 28th, 2007, 04:17 PM
Friend of Wrox
 
Join Date: Mar 2004
Posts: 3,069
Thanks: 0
Thanked 10 Times in 10 Posts
Default

I just called it Form1.

I can send you the database to see if it works in your environment. Are you using 2003?

mmcdonal

Look it up at: http://wrox.books24x7.com
 
Old December 28th, 2007, 04:27 PM
Authorized User
 
Join Date: Nov 2006
Posts: 21
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Yes, I'm using 2003.

Can you just send it to me?

[email protected]

Tks,

John

 
Old January 2nd, 2008, 12:49 PM
Authorized User
 
Join Date: Nov 2006
Posts: 21
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Happy New Year!!

O.K. I have started from scratch.

I created a form. I called it Form1. On the form "On Load" I created an [Event Procedure].

I used the wizard and created a frame object with 6 pushbuttons. I named them Toggle0-Toggle5.

I have copied the code where you indicated you went overboard on. I tried to compile and get the following error;

On the Form_Load() I get a compile error with Me.Text5 = "No Actions Processed" highlighted as the error and the error popup screen indicates taht the "Method or Data Member not found".

So, What am I doing wrong?

Tks,

John




 
Old January 2nd, 2008, 12:55 PM
Friend of Wrox
 
Join Date: Mar 2004
Posts: 3,069
Thanks: 0
Thanked 10 Times in 10 Posts
Default

I emailed the database. Sorry for the confusion.

mmcdonal

Look it up at: http://wrox.books24x7.com





Similar Threads
Thread Thread Starter Forum Replies Last Post
Figuring out which values don't match ninel SQL Server 2000 7 May 12th, 2006 01:26 AM
parsing form data from frame to other frame audio-catalyst Classic ASP Basics 5 January 3rd, 2006 02:57 PM
HELP, I am having trouble figuring out how to.. nvillare VB.NET 2002/2003 Basics 6 March 13th, 2005 08:09 PM
Call right frame Page_Load event from left frame. ochanarachel Classic ASP Basics 0 January 28th, 2005 05:13 AM
Bound Object Frame Property Needed SerranoG Access VBA 0 April 16th, 2004 10:42 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.