Select a Macro using VB (1 Viewer)

Sander

Registered User.
Local time
Today, 20:10
Joined
Jun 6, 2001
Messages
20
If anyone can help me I'd very much appreciate it. I'm really rust where VB is concerned and my book isn't helping much.

I have a form called NonBargainingView. Within the form is a text box called Degree.

When a command button is pushed (called Command23) I want Access to look and see if the word Graduate is in Degree. If it is I want a macro called NonBargGradTax to run. If anything else is in the box I want the macro NonBargGradTax to run.

I know my problem lies in looking at the Degree box (at least that's where I'm getting my errors) but I don't have a clue as to how to fix it. I've guessed as to what I'm suppose to declare everything. Is that where I'm going wrong?

Thank You in Advance for any help!

Private Sub Command23_Click()

Dim NonBargainingView As Form
Dim Degree As TextBox
Dim Grad As String
Dim Under As String

Grad = "NonBargGradTax"
Under = "NonBargGradTax"

If NonBargainingView.Degree = "Graduate" Then
DoCmd.RunMacro Grad
Else
DoCmd.RunMacro Under
End If

End Sub
 

Travis

Registered User.
Local time
Today, 12:10
Joined
Dec 17, 1999
Messages
1,332
You set Degree as a Textbox, but you don't set which one it is, you do the same for the form:

Try this

Set Degree=Me.Control("NameofControl")

If Degree = "Graduate" Then
DoCmd.RunMacro Grad
Else
DoCmd.RunMacro Under
End If
 

Sander

Registered User.
Local time
Today, 20:10
Joined
Jun 6, 2001
Messages
20
I'm not totally sure what you mean by NameOfControl. I tried entering the text box name and I tried entering the form name and neither work. I keep getting a compile error:

Method or data member not found.

Highlighted in yellow is:
Priate Sub Command23_Click()

Highlighted in Blue is:
.Control

I never realized how much of VB I forgot until I started trying to do this...
 

Travis

Registered User.
Local time
Today, 12:10
Joined
Dec 17, 1999
Messages
1,332
It should be

Set Degree=Me.Controls("NameofControl")

The "NameofControl" is the name that the Text box has on your form.

By doing it this way Degree becomes a reference to your control.
 

Sander

Registered User.
Local time
Today, 20:10
Joined
Jun 6, 2001
Messages
20
It works! Thank You very much for your help. I really appreciate it!
 

Users who are viewing this thread

Top Bottom