views:

102

answers:

3

making an Access database (2003) that is mainly used by other programmers and tech management as a tool for data validation. I want to put an button on parts of the form that runs code, to show the code that is being run. So the programmers can edit it on the spot. This is for a data validation project with frequent changing of code. Lets assume the code is in a module so the form doesn't need to be saved or in edit mode. Just push the button and up pops the code in code view.

A: 

Would it work for you?

Private Sub Command0_Click()
While True
Debug.Print "tt"
If pressed And debugmode Then
   Stop
   pressed = False
End If
DoEvents

Wend
End Sub

Private Sub Command1_Click()
    pressed = True
    ' You can just put here Stop 
End Sub

Edit: I mean use DoEvents and Stop

THEn
A: 

Hi Avraham,
Viewing the code is not so hard, and really neither is editing it. But I should warn you off a few pitfalls. First, the approach you are discussing amounts to self modifying code which will trip a lot of Antivirus software. Secondly corruption is a constant danger with Access and self modifying code only exacerbates this problem. Any solution you come up with should minimize edits and you should also have a very robust backup and restoration plan. Thirdly self modifying code will prevent you from compiling the database (using mdes) or locking the project. This can lead to some very hard to control and maintain source code.
I would suggest instead that you consider using Pure SQL to do your data modification. You can then store and modify the SQL in a table and then just use CurrentDB.Execute to run it.

Oorang
I don't want to modify the code in code, just display it in the vba editor. For example, if I have a EditDataCust() function in module "basEditTools", I want the access vba environment to open up, showing that module and the curser at EditDataCust(). I want to tHAT in code.
Avraham
I meant to say, I want to do THAT in code.
Avraham
+1  A: 

You may be limited to only code in modules. But in a button on the form, you could set the click event to:

DoCmd.OpenModule "module_name", "the_name_of_some_function"

Jeff O
That's it! Thank you.
Avraham