Solved

changing the executable code behind a button on the fly

Posted on 2012-03-12
3
390 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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I'm trying, I really am. But I've seen so many wrong approaches involving date(time) boundaries I despair about my inability to explain it. I've seen quite a few recently that define a non-leap year as 364 days, or 366 days and the list goes on. …
You need to know the location of the Office templates folder, so that when you create new templates, they are saved to that location, and thus are available for selection when creating new documents.  The steps to find the Templates folder path are …
In Microsoft Access, learn the trick to repeating sub-report headings at the top of each page. The problem with sub-reports and headings: Add a dummy group to the sub report using the expression =1: Set the “Repeat Section” property of the dummy…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

749 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