DoCmd.RunMacro code help?

  • Thread starter Thread starter GD
  • Start date Start date
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!!
 
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
 
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
 
Back
Top