VBA to populate fileds with vaules when using the on-click func for a toggle button?

Goli

New member
Local time
Today, 15:22
Joined
Jan 21, 2008
Messages
6
Hi there,

I'm brand new to this so be gentle :( , - I'v been using Access for a short time now and have been shown VBA briefly! -
I have a db in which I'd like to try something but I don't know where to start?

What i'd like to do is use the on-click func for a toggle button to create defualt values such as (N/A) in other fields on a form?

The grand Idea is this - When a user hits the toggle button on a form it will populate the fields which do not apply with a defualt (hence clicking on the toggle button) and move the user on to the next tab-or relavent field.

Any Ideas?

I am most probably making life difficult for myself but any help would be greatly appreciated.

Goli.
 
Here's a sample of code for you Goli:
Code:
Private Sub ToggleButtonName_Click()

dim c as control

  [B]if[/B] [i]the "does not apply" condition is true[/I] [B]then[/B]

    me.Field1Name = "N/A"
      me.Field2Name = "N/A"
        etc...

  end if

  for each c in me.controls
    if not isnull(c) then
      [color=red]if not typeof c is label then[/color]
        c.setfocus
          exit for
      end if
    end if
  next

End Sub
Make sure the tab order of the controls on the form is set to the sequence you want before you execute a loop like that.
 
Last edited:
Code:
dim c as control


  for each c in me.controls
    if not isnull(c) then
      c.setfocus
        exit for
    end if
  next

End Sub
Adam - this code will generate an error if any control is on the form that can't have focus (like a label) so you would need to modify it so that it excluded those controls.
 
Sorry Bob! Fixed it...

To tell you the truth though, with a question like this one, I'm not sure if we should go that far yet... :)
 

Users who are viewing this thread

Back
Top Bottom