Re: Call a subroutine
From: Rick Rothstein (rickNOSPAMnews_at_NOSPAMcomcast.net)
Date: 04/23/04
- Next message: solex: "Re: Call a subroutine"
- Previous message: Bob Butler: "Re: varieble value --> object name"
- In reply to: Billy: "Re: Call a subroutine"
- Next in thread: Randy Birch: "Re: Call a subroutine"
- Reply: Randy Birch: "Re: Call a subroutine"
- Messages sorted by: [ date ] [ thread ]
Date: Fri, 23 Apr 2004 10:02:49 -0400
> I have a form with check boxes on it. These checkboxes represent tables
where I want to move data from one table in one database to another tablein
another database (the tables are the same name BUT not the same structure).
>
> The routine is part of a data conversion plan between and old system and a
new system. The table names are fixed and the therefore I had them setup on
the form as checkboxes. Then, depending what the user was to click on (1 or
all), the code would loop through the checkboxes and, if it were checked,
call the procedure for that checkbox....the easiest solution being a routine
of the same name. That routine has code to specifically move data from a
table in one database to a table in another database. Hence the
>
> Private Sub cmdTransfer_Click()
> Dim x As Integer
>
> 'which option was checked
> For x = 0 To optTable.Count - 1
> If optTable(x).Value = True Then
> Call optTable(x).Caption
> End If
> Next
> End Sub
>
> The optTable(i).Caption is the name of the routine to call.
>
> This routine is not commercial. It's simply a tool I will need to use more
than once to move data from one table to another in different databases.
>
> The tables are in Access.
I notice you changed from using CheckBox'es to using OptionButton's... good,
that took care of one of my comments.<g> As for your set up, how about
putting this in your CommandButton's click event...
Private Sub Command1_Click()
Dim x As Long
For x = 0 To optTable.UBound
If optTable(x).Value Then
Select Case optTable.Value
Case 0
Call <<routine for optTable(0) here>>
Case 1
Call <<routine for optTable(1) here>>
Case 2
Call <<routine for optTable(2) here>>
Case ...etc...
Call <<....etc....>>
End Select
Exit For
End If
Next
End Sub
Notice I used optTable.Ubound instead of optTable.Count-1 in the For
statement part of the For-Next loop. Now, the above is suitable for a small
number of OptionButton's. If you have a large number of them, there is
another tact you can take. Declare a variable with Form-wide scope (that is,
Dim it in the Form's General-Declarations section), and set it in the Click
event of the OptionButton; then react to it in the CommandButton's Click
event. Something like this
Dim WhichOption As Long
Private Sub optTable_Click(Index As Integer)
WhichOption = Index
End Sub
Private Sub Command1_Click()
Dim x As Integer
Select Case WhichOption
Case 0
Call <<routine for optTable(0) here>>
Case 1
Call <<routine for optTable(1) here>>
Case 2
Call <<routine for optTable(2) here>>
Case ...etc...
Call <<....etc....>>
End Select
End Sub
This is overall the same as the first method, but it eliminates the need for
the For-Next loop. By calling the routines in the Select Case, you remove
the dependence of keeping the OptionButton Caption's the same as the routine
names. This allows you to use more descriptive Captions; that is, more
easily read phrases and/or sentences with spaces in them.
Rick - MVP
- Next message: solex: "Re: Call a subroutine"
- Previous message: Bob Butler: "Re: varieble value --> object name"
- In reply to: Billy: "Re: Call a subroutine"
- Next in thread: Randy Birch: "Re: Call a subroutine"
- Reply: Randy Birch: "Re: Call a subroutine"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|