Run vba code or routine stored into field (1 Viewer)

gstylianou

Registered User.
Local time
Today, 17:53
Joined
Dec 16, 2013
Messages
357
Good Evening,

Is it possible to executed a vba code or routine which has been stored into a field (Long Text Field) ? I would like to run the code through a standard command Button. Is that possible and if so, how?

Attached there is an example of the code to wish run:

Private Sub Form_Load ()
'
If me.ControlLang = 1 Then
cmdLanguage (1)
ElseIf me.ControlLang = 2 Then
cmdLanguage (2)
End If

End Sub
 

Gasman

Enthusiastic Amateur
Local time
Today, 15:53
Joined
Sep 21, 2011
Messages
14,395
Why not just have
Code:
cmdLanguage(Me.ControlLang)
 

gstylianou

Registered User.
Local time
Today, 17:53
Joined
Dec 16, 2013
Messages
357
Why not just have
Code:
cmdLanguage(Me.ControlLang)
Gasman it was just an example....... lets give you another example.
I wanted to open the form "Invoices" by pressings the button.....but the this command must be taken from the field...
 

gstylianou

Registered User.
Local time
Today, 17:53
Joined
Dec 16, 2013
Messages
357
It's considered a hack and poor programming practices, but there is the Eval function:

Hi plog,

I found this code but really i don't know how help me...


Dim ctl As Control
Dim varTemp As Variant
Set ctl = Forms!Contacts!HelpButton
If (Left(ctl.OnClick, 1) = "=") Then
varTemp = Eval(Mid(ctl.OnClick,2))
Else
DoCmd.RunMacro ctl.OnClick
End If

Is this example similar on my demand? Is it possiple somebody to attached me a smal accdb example?

Thanks all
 

theDBguy

I’m here to help
Staff member
Local time
Today, 07:53
Joined
Oct 29, 2018
Messages
21,515
Hi. Just a guess, but I think the only way you'll get what you want is by using VBA extensibility where you dynamically create and execute code modules. Just a thought...

PS. It's more acceptable to create all the logic in the code and simply pass data to it from your database.
 

gstylianou

Registered User.
Local time
Today, 17:53
Joined
Dec 16, 2013
Messages
357
Hi. Just a guess, but I think the only way you'll get what you want is by using VBA extensibility where you dynamically create and execute code modules. Just a thought...

PS. It's more acceptable to create all the logic in the code and simply pass data to it from your database.
DBguy,

Because of my poor knowledge of vba, can i ask you what actually i must do? (by using VBA extensibility)
 

theDBguy

I’m here to help
Staff member
Local time
Today, 07:53
Joined
Oct 29, 2018
Messages
21,515
DBguy,

Because of my poor knowledge of vba, can i ask you what actually i must do? (by using VBA extensibility)
First, let me ask you. Are you planning to distribute compiled versions of your database, so people won't be able to get to your code? If so, you wouldn't want to go down this road.
 

Pat Hartman

Super Moderator
Staff member
Local time
Today, 10:53
Joined
Feb 19, 2002
Messages
43,408
I wanted to open the form "Invoices" by pressings the button.....but the this command must be taken from the field...
How would the users know the correct VBA command to open a form? They would have to in order to use Eval() to run the code. If you are talking about using a variable in the OpenForm, that's a whole different thing.

DoCmd.OpenForm Me.SomeFormField

This would open the form whose name is in the SomeFormField control.

Also, what is "from the field"? Are they not on your LAN but want to use your Access application? You should look into using Citrix or remote Desktop. Both allow your app to run in a web browser.
 

gstylianou

Registered User.
Local time
Today, 17:53
Joined
Dec 16, 2013
Messages
357
First, let me ask you. Are you planning to distribute compiled versions of your database, so people won't be able to get to your code? If so, you wouldn't want to go down this road.
First thanks,

You know, i'm looking to find this solution on order to modify my future accde file without needs to re-install it from the beginnig.....
 

theDBguy

I’m here to help
Staff member
Local time
Today, 07:53
Joined
Oct 29, 2018
Messages
21,515
First thanks,

You know, i'm looking to find this solution on order to modify my future accde file without needs to re-install it from the beginnig.....
Well, then, VBA Extensibility is probably not for you. As I said earlier, it's easier to put the logic in the code and provide the data.

For example, think about how the old Switchboard used to work. Anyone can create their own menu and decide whether to open a form or a report or open a submenu. That's what I was talking about putting the logic in the code and only provide the data to make it do different things.

Hope that helps...
 

gstylianou

Registered User.
Local time
Today, 17:53
Joined
Dec 16, 2013
Messages
357
Well, then, VBA Extensibility is probably not for you. As I said earlier, it's easier to put the logic in the code and provide the data.

For example, think about how the old Switchboard used to work. Anyone can create their own menu and decide whether to open a form or a report or open a submenu. That's what I was talking about putting the logic in the code and only provide the data to make it do different things.

Hope that helps...
Just to learn, what exactly is the VBA Extensibility
 

The_Doc_Man

Immoderate Moderator
Staff member
Local time
Today, 09:53
Joined
Feb 28, 2001
Messages
27,270
You know, i'm looking to find this solution on order to modify my future accde file without needs to re-install it from the beginnig.....

Hate to burst your bubble here, but that isn't a realistic view of the way Access databases are maintained. The TYPICAL method is that you have a central location and when someone wants to run the DB, they copy the latest version from the "official" location and just run it. There is normally no "Install" involved because it is MS Access itself that opens the APP. You don't change Access, which MUST be installed. You just change the contents of the application file and Access opens it by name. So "re-install it from the beginning" is more like "copy a new version in a matter of a few seconds."

Further, if you were REALLY sending out an ACCDE but had code in text boxes or combo boxes or such, there ceases to be a security advantage to using .ACCDE over .ACCDB - because you give folks the ability to change what Access does DESPITE it being a pre-compiled DB.
 

Pat Hartman

Super Moderator
Staff member
Local time
Today, 10:53
Joined
Feb 19, 2002
Messages
43,408
You know, i'm looking to find this solution on order to modify my future accde file without needs to re-install it from the beginnig.....
Doc beat me to it. This is a poor idea. There are very easy ways to update the FE so there is no need to do this. In fact, it is a serious security issue. This is how web sites get hacked.
 

MajP

You've got your good things, and you've got mine.
Local time
Today, 10:53
Joined
May 21, 2018
Messages
8,555
Your idea makes no sense, but the solution I provided will work if that is the way you want to go.
 

gstylianou

Registered User.
Local time
Today, 17:53
Joined
Dec 16, 2013
Messages
357
As I understood this code must be stored into a filed or not ?

Option Explicit Private Sub Form_Load() Label1.Caption = "Move" ' Name of Move method. End Sub Private Sub Command1_Click() If Command1.Left <> 0 Then CallByName Command1, Label1.Caption, vbMethod, 0, 0 Else CallByName Command1, Label1.Caption, vbMethod, 500, 500 End If

And what is the command to execute

Thanks again
 

MajP

You've got your good things, and you've got mine.
Local time
Today, 10:53
Joined
May 21, 2018
Messages
8,555
After rereading your post. Use the application.run method. See demo
 

Attachments

  • ApplicationRun.accdb
    380 KB · Views: 122

gstylianou

Registered User.
Local time
Today, 17:53
Joined
Dec 16, 2013
Messages
357
After rereading your post. Use the application.run method. See demo
Hi MajP,

First all thanks for your time to prepare the sample accdb file. Moreover, i understood the logic idea on how can work with Application.Run but what i'm looking to find is the solution to write the vba procedure into field and then to execute it using command. As an example,

I have the field [VBACode] which has been stored inside the following simple code lines, is it possible to run this by using the command?

Public Sub GoodMorningWorld()
MsgBox "Good Morning World"
End Sub
 

Users who are viewing this thread

Top Bottom