Solved

changing the executable code behind a button on the fly

Posted on 2012-03-12
3
386 Views
Last Modified: 2012-03-12
what is the proper syntax to set the value of a button/control to difference functions depending on which phase of the the process the user is in?

I am in the process of converting and cleaning up old Macro code into vba.  It does not like the setting of a control/button.

I have a form where the "ok" button could launch 1 of 3 functions to be used.  Like if field 3  = FTIRDN then it should execute the function named:  FM_ViDataX_ApSelect_FTIR_OK

Private Sub cmd_ImportFTIR_Click()

Dim i As Integer
   
   On Error GoTo cmd_ImportFTIR_Click_Error
    
    gApNO = Me.ApNo
    ' FM_ViDataX_ApSelect - Form - - - Edit - Normal ==> Self Explanatory
    DoCmd.OpenForm "FM_ViDataX_ApSelect", acNormal, "", "", acEdit, acNormal
    '-- Set the initial form values.
    Forms![FM_ViDataX_ApSelect]![txtApNo].Value = UCase$(Trim$(gApNO))
    Forms![FM_ViDataX_ApSelect]![txtFileName].Value = gApNO & "\Access\FTIR.txt"
    ' ViDataX_Set_FTIR_Values - Code ==> Set the default FTIR download values for FM_ViDataX_ApSelect form.
    Forms![FM_ViDataX_ApSelect]![txtXactnName].Value = "FTIRDN"
    ' Sets the click event on the OK button to run FM_ViDataX_ApSelect._FTIR_OK
    i = 1
 '   Forms!FM_ViDataX_ApSelect!cmdOK.OnClick = "FM_ViDataX_ApSelect_FTIR_OK"

   On Error GoTo 0
   Exit Sub

cmd_ImportFTIR_Click_Error:

    MsgBox "Error " & Err.Number & " (" & Err.Description & ") in procedure cmd_ImportFTIR_Click of VBA Document Form_FS_MSB"

End Sub

Open in new window


As you can see I have tried it within the quotes and it gives me an error msg.  Can't find the object FM_ViDataX_ApSelect_FTIR_OK

and if I try it w/o the quotes then it just executes the code automatically.

Please keep in mind that this OK button should be used in 3 different instances using different function names.  What is the proper syntax?

Karen
0
Comment
Question by:Karen Schaefer
  • 2
3 Comments
 
LVL 15

Accepted Solution

by:
Simon Ball earned 500 total points
ID: 37711968
in the button click event use

select case <variable>

case <variable> = 1
'do some work
case <variable> = 2
'do some work
Case else
'do some work
end select

to handle which stage the page is in when button clicked.

you just use a public variable to hold a record of page stage
0
 

Author Closing Comment

by:Karen Schaefer
ID: 37712098
we were on the same page.  thanks for your input.
0
 
LVL 15

Expert Comment

by:Simon Ball
ID: 37712105
thanks! :P
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

I see at least one EE question a week that pertains to using temporary tables in MS Access.  But surprisingly, I was unable to find a single article devoted solely to this topic. I don’t intend to describe all of the uses of temporary tables in t…
Confronted with some SQL you don't know can be a daunting task. It can be even more daunting if that SQL carries some of the old secret codes used in the Ye Olde query syntax, such as: (+)     as used in Oracle;     *=     =*    as used in Sybase …
Learn how to number pages in an Access report over each group. Activate two pass printing by referencing the pages property: Add code to the Page Footers OnFormat event to capture the pages as there occur for each group. Use the pages property to …
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now