Welcome guest. Before posting on our computer help forum, you must register. Click here it's easy and free.

Author Topic: Ms Access - Pass value in form to subroutine.  (Read 5769 times)

0 Members and 1 Guest are viewing this topic.

Rodger

  • Guest
Ms Access - Pass value in form to subroutine.
« on: February 18, 2005, 03:04:43 PM »
I have added a VBA Command Button to a Form in a MS Access Database.  The Command Button executes the following code when clicked.

Private Sub CreateDir_Click()
On Error GoTo Err_CreateDir_Click

   Dim stAppName As String

   stAppName = "P:\ZNewProject.bat"
   Call Shell(stAppName, 1)

Exit_CreateDir_Click:
   Exit Sub

Err_CreateDir_Click:
   MsgBox Err.Description
   Resume Exit_CreateDir_Click
   
End Sub

I would like to pass the value found in one of the Form fields to the batch file.

Any Ideas?

gussery

  • Guest
Re: Ms Access - Pass value in form to subroutine.
« Reply #1 on: February 18, 2005, 03:24:48 PM »
create a variable to store the value in and then pass it assuming, of course, your batch file can "catch" it.  Something like.

Private Sub CreateDir_Click()
On Error GoTo Err_CreateDir_Click

   Dim stAppName As String
   Dim stValue as String
   
    stValue = me.text1


   stAppName = "P:\ZNewProject.bat"  & " " & stValue
   Call Shell(stAppName, 1)

Exit_CreateDir_Click:
   Exit Sub

Err_CreateDir_Click:
   MsgBox Err.Description
   Resume Exit_CreateDir_Click
   
End Sub


The value is then concatenated onto stAppName in your case.



Gary

Rodger

  • Guest
Re: Ms Access - Pass value in form to subroutine.
« Reply #2 on: February 18, 2005, 04:05:28 PM »
I understand that part I guess my question was difficult to understand.  I'll try again.

The part I am having difficulty with is with the line

stValue = me.text1

The "me.text1" is actually a value that is input into the form field named EA on the Access Form.

So how do I extract the value of the Field called EA from the Record being viewed in the Access Form?  

gussery

  • Guest
Re: Ms Access - Pass value in form to subroutine.
« Reply #3 on: February 18, 2005, 04:36:22 PM »
me. = the current form
the next part is the name of the control.  I used text1 as an example.

So assuming that field you want to read from on the form is named EA.  Then you refer to the form field as me.EA.

If you want to extract the value you do.

somevariable = me.EA

if you want to put something in it you do...

me.EA.value = somevariable.

Be careful if your form is bound to a table and you let Access name the fields for you.  You will find that it names the form field the same as the column name in the table and will cause confusion for you and Access.


Rodger

  • Guest
Re: Ms Access - Pass value in form to subroutine.
« Reply #4 on: February 18, 2005, 05:05:41 PM »
 ;D
Thanks a Million Gussery, it works like a charm!!!!!!!!!!
(Sorry I misunderstood the Me.text)





gussery

  • Guest
Re: Ms Access - Pass value in form to subroutine.
« Reply #5 on: February 18, 2005, 05:21:46 PM »
You're welcome.

Happy computing...........

Gary