Computer Hope

Software => Computer programming => Topic started by: Rodger on February 18, 2005, 03:04:43 PM

Title: Ms Access - Pass value in form to subroutine.
Post by: Rodger 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?
Title: Re: Ms Access - Pass value in form to subroutine.
Post by: gussery 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
Title: Re: Ms Access - Pass value in form to subroutine.
Post by: Rodger 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?  
Title: Re: Ms Access - Pass value in form to subroutine.
Post by: gussery 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.

Title: Re: Ms Access - Pass value in form to subroutine.
Post by: Rodger on February 18, 2005, 05:05:41 PM
 ;D
Thanks a Million Gussery, it works like a charm!!!!!!!!!!
(Sorry I misunderstood the Me.text)




Title: Re: Ms Access - Pass value in form to subroutine.
Post by: gussery on February 18, 2005, 05:21:46 PM
You're welcome.

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

Gary