Author Topic: VB Application  (Read 2159 times)

0 Members and 1 Guest are viewing this topic.

krampaul82

  • Guest
VB Application
« on: November 30, 2009, 06:09:40 PM »
To whom it may concern,
I have a form with a command button and several check boxes in order on the form.
if any check box = 1 or true the program calls a sub (in a Module) that gets specific Input / Values from the user
and writes that input to specific cells in an excel worksheet. when that is done I want the program to get back to the next checkbox
that = 1 or true on the home form and call a new sub (in a module) that gets specific Input / Values from the user. When that is done I want the program to get back to the next checkbox that = true etc.

example

sub Cmd_ahu_click()

if Chkbox1 = 1 then
ahu_ choices1            'found in seperate module when done in module  goto the next elseif chkbox2 statement

elseif Chkbox2 = 1 then
ahu_choices2              'found in seperate module when done in module  goto the next elseif chkbox3statement

elseif Chkbox3 = 1 then
ahu_choices3              'found in seperate module when done in module  go back to the home form for more choices.

else: no_options_picked

end sub

Any Help would be appreciated

Mark



Keith™

  • Villiage Idiot
  • Seagull
  • Posts: 16899
  • Superior Stupidity at its best
Re: VB Application
« Reply #1 on: December 01, 2009, 08:42:21 AM »
well, that won't do it .... the if .. then .. else will only evaluate the items in order and ignore the rest of the items .. but I suspect you already found that out or you wouldn't be posting here ...

If you know the number of checkboxes, you can separate each into individual if .. then statements ..

Code: [Select]
If Chkbox1.Value = True Then
 'Do Stuff
End If
If Chkbox2.Value = True Then
 'Do Stuff
End If
If Chkbox3.Value = True Then
 'Do Stuff
End If

However, a more desirable way might be to use the event handler of each checkbox ...
Code: [Select]
Private Sub Chkbox1_Click ()
 If Chkbox1.Value = True Then
  'Do Stuff
 Else
  'Undo Stuff
 End If
End Sub

Then what you would do is store the values of each checkbox when the application starts, and if the user cancels, reset the values of the checkboxes causing the undo action to execute.

There are other ways of doing it too, like looping through the controls and do an action based on the control name

Code: [Select]
'Put this code in a sub that is executed at form closing time, when it wasn't cancelled
Dim cntrl As Control
For Each cntrl In MyForm.Controls 'Change this to your own form name
  Select Case cntrl.Name
   Case "Chkbox1"
     'Do Stuff
   Case "Chkbox2"
     'Do Stuff
   Case "Chkbox3"
     'Do Stuff
   Case Else
     'Do Stuff
  End Select
Next cntrl

Good Luck
Proud provider of opinion and arrogance since November 22, 2003 at 09:35:31 am
CadJockey Militia Field Marshal

Find me on https://parler.com @kblackie

krampaul82

  • Guest
Re: VB Application
« Reply #2 on: December 01, 2009, 10:18:14 AM »
Keith,
thank you for you response see attachment at your leisure
this is the infancy stage of an attempt to code in vb. very new at this.
thank you,
Mark.