By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,378 Members | 3,020 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,378 IT Pros & Developers. It's quick & easy.

Run code from field

P: n/a
I've created an Access 2000 database. I want to have a Scripts/Macro
section to automate certain tasks for users. If a user has a specific
task they want done periodically, they can run a script/macro. The
script/macro code will be given to them by me and stored in a Memo
field eg.

Forms!frmMainMenu.cmdSearch_Click
.....
Forms!frmMainMenu.cmdClose_Click

I want to be able to run the code that is stored in this Memo field.
The file is an MDE so I can't use LoadFromFile to create a macro in
VBA. I don't know any way to run this code with an MDE. Has anyone got
any ideas?

Thanks,

Chris

May 4 '06 #1
Share this Question
Share on Google+
2 Replies


P: n/a
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Perhaps, instead of storing the data in the target DB you just sent
another .mde or .mdb file w/ the code. The code would be set up to
control the target DB thru Automation. Read the VBA Help articles on
the GetObject function.
--
MGFoster:::mgf00 <at> earthlink <decimal-point> net
Oakland, CA (USA)

-----BEGIN PGP SIGNATURE-----
Version: PGP for Personal Privacy 5.0
Charset: noconv

iQA/AwUBRFpgN4echKqOuFEgEQLYAgCffCKRXlEP7QoTvh19mSLjGR mFyAAAoOIK
s8TIHE9MVO+sdD+ifLQ39Hbl
=4gaD
-----END PGP SIGNATURE-----
ch*******@hotmail.com wrote:
I've created an Access 2000 database. I want to have a Scripts/Macro
section to automate certain tasks for users. If a user has a specific
task they want done periodically, they can run a script/macro. The
script/macro code will be given to them by me and stored in a Memo
field eg.

Forms!frmMainMenu.cmdSearch_Click
....
Forms!frmMainMenu.cmdClose_Click

I want to be able to run the code that is stored in this Memo field.
The file is an MDE so I can't use LoadFromFile to create a macro in
VBA. I don't know any way to run this code with an MDE. Has anyone got
any ideas?

May 4 '06 #2

P: n/a
Thanks for your response. I got an idea from it. I wanted to avoid
using another mdb/mde and came up with a solution. I decided to create
my own sort of scripting language for my application. eg.
Event Open Candidate
Event Click cmdTest
V frmCandidate,chkOne,chk,-1
Event Click One
S UPDATE tblOne SET field1 = "test"
Finish

I just have to make the common events Public rather than Private
It can run events, run sql and assign values to controls.

Public Sub cmdRunScript_Click()
Dim scriptline As String
Dim remainingscriptline As String
Dim remainingtext As String
Dim valuestring As String
Dim remainingvaluestring As String
Dim fn As String
Dim ctr As String
Dim ctrtype As String
Dim val As String

remainingtext = txtMemo

scriptline = Left(remainingtext, InStr(remainingtext, vbCrLf) - 1)

While Not scriptline = "" And Not Len(scriptline) = 0
Select Case Left(scriptline, 1)
Case "V"
' in the format <V formname control value>
valuestring = Right(scriptline, Len(scriptline) - 2)
fn = Left(valuestring, InStr(valuestring, ",") - 1)
remainingvaluestring = Right(valuestring, Len(valuestring)
- InStr(valuestring, ","))
ctr = Left(remainingvaluestring,
InStr(remainingvaluestring, ",") - 1)
remainingvaluestring = Right(remainingvaluestring,
Len(remainingvaluestring) - InStr(remainingvaluestring, ","))
ctrtype = Left(remainingvaluestring,
InStr(remainingvaluestring, ",") - 1)
val = Right(remainingvaluestring, Len(remainingvaluestring)
- InStr(remainingvaluestring, ","))
AssignValue fn, ctr, ctrtype, val
Case "E"
Select Case scriptline
Case "Event Open Candidate"
Call Forms("frmMainMenu").cmdCandidate_Click
Case "Event Click cmdTest"
Call Forms("frmCandidate").cmdTest_Click
Case "Event Click One"
Call Forms("frmCandidate").chkOne_Click
End Select
Case "SQL "
DoCmd.SetWarnings False
DoCmd.RunSQL Right(scriptline, Len(scriptline) - 2)
Case "F"
' end of script
scriptline = ""
End Select

remainingtext = Right(remainingtext, Len(remainingtext) -
InStr(remainingtext, vbCrLf) - 1)
If InStr(remainingtext, vbCrLf) <> 0 Then
scriptline = Left(remainingtext, InStr(remainingtext, vbCrLf) -
1)
Else
scriptline = remainingtext
End If
Wend

End Sub
Public Sub AssignValue(fn As String, ctr As String, ctrtype As String,
val As String)
Select Case ctrtype
Case "txt"
Case "cmb"
Case "lst"
Case "chk"
Forms(fn).Controls(ctr) = val
Case "opt"
End Select
End Sub

MGFoster wrote:
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Perhaps, instead of storing the data in the target DB you just sent
another .mde or .mdb file w/ the code. The code would be set up to
control the target DB thru Automation. Read the VBA Help articles on
the GetObject function.
--
MGFoster:::mgf00 <at> earthlink <decimal-point> net
Oakland, CA (USA)

-----BEGIN PGP SIGNATURE-----
Version: PGP for Personal Privacy 5.0
Charset: noconv

iQA/AwUBRFpgN4echKqOuFEgEQLYAgCffCKRXlEP7QoTvh19mSLjGR mFyAAAoOIK
s8TIHE9MVO+sdD+ifLQ39Hbl
=4gaD
-----END PGP SIGNATURE-----
ch*******@hotmail.com wrote:
I've created an Access 2000 database. I want to have a Scripts/Macro
section to automate certain tasks for users. If a user has a specific
task they want done periodically, they can run a script/macro. The
script/macro code will be given to them by me and stored in a Memo
field eg.

Forms!frmMainMenu.cmdSearch_Click
....
Forms!frmMainMenu.cmdClose_Click

I want to be able to run the code that is stored in this Memo field.
The file is an MDE so I can't use LoadFromFile to create a macro in
VBA. I don't know any way to run this code with an MDE. Has anyone got
any ideas?


May 5 '06 #3

This discussion thread is closed

Replies have been disabled for this discussion.