DoCmd.RunMacro code help?

G

GD

I'm trying to run some simple code (at least it should be!). If
txtVendorKeyword is empty, I need macro M02_RunQryMASTER run. And if there
is a text string there, I need macro M03_CMDMProject run. Here's what I have:

Private Sub cmdSearchAP_Click()
If Me.txtVendorKeyword Is Not Null Then
DoCmd.RunMacro "M03_CMDMSearch"
Else
DoCmd.RunMacro "M02_RunQryMASTER"
End If
End Sub

Nothing happens when I click the command button. What am I doing wrong?
THANKS!!
 
J

John Spencer MVP

IN code you must use the VBA function IsNull() to test the value.

Private Sub cmdSearchAP_Click()
If IsNull(Me.txtVendorKeyword) = False Then
DoCmd.RunMacro "M03_CMDMSearch"
Else
DoCmd.RunMacro "M02_RunQryMASTER"
End If
End Sub

As an alternative you can check the length of txtVendorKeyword

Private Sub cmdSearchAP_Click()
If Len(Me.txtVendorKeyword & "") > 0 Then
DoCmd.RunMacro "M03_CMDMSearch"
Else
DoCmd.RunMacro "M02_RunQryMASTER"
End If
End Sub
John Spencer
Access MVP 2002-2005, 2007-2009
The Hilltop Institute
University of Maryland Baltimore County
 
G

GD

Works great!! You're a lifesaver!
--
GD


John Spencer MVP said:
IN code you must use the VBA function IsNull() to test the value.

Private Sub cmdSearchAP_Click()
If IsNull(Me.txtVendorKeyword) = False Then
DoCmd.RunMacro "M03_CMDMSearch"
Else
DoCmd.RunMacro "M02_RunQryMASTER"
End If
End Sub

As an alternative you can check the length of txtVendorKeyword

Private Sub cmdSearchAP_Click()
If Len(Me.txtVendorKeyword & "") > 0 Then
DoCmd.RunMacro "M03_CMDMSearch"
Else
DoCmd.RunMacro "M02_RunQryMASTER"
End If
End Sub
John Spencer
Access MVP 2002-2005, 2007-2009
The Hilltop Institute
University of Maryland Baltimore County
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Top