A Microsoft Office (Excel, Word) forum. OfficeFrustration

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

Go Back   Home » OfficeFrustration forum » Microsoft Access » New Users
Site Map Home Register Authors List Search Today's Posts Mark Forums Read  

macro help



 
 
Thread Tools Display Modes
  #1  
Old June 3rd, 2010, 12:36 PM posted to microsoft.public.access.gettingstarted
mick
external usenet poster
 
Posts: 2
Default macro help

I have a "customers input form" for entering name, address, ref no.,
etc.
I have an "order form" with a text box into which can be manually
entered a customer reference number when needed. Next to the box is a
button that when activated opens the "customers input form" displaying
the customer details.
The macro for the button is:
OpenForm
form name, customers input
where condition, ="[CRN]=" & [CRN]

This works fine, except when the button is activated and there is
nothing in the text box, there is then a syntax error and the macro has
to be stopped manually.

Question is; what do I need to add to the macro to prevent the error
happening when the text box is empty and the button is activated?

Thanks.

--
mick


  #2  
Old June 3rd, 2010, 08:58 PM posted to microsoft.public.access.gettingstarted
tighe
external usenet poster
 
Posts: 53
Default macro help

mick.

i have to admit i dont use the where condition(it might be where the quotes
are) but you could handle this On Load of the "customers input form" with vba:

Sub Form_Load()
If IsLoaded("[order form]") = True Then
me.filter="[CRN]=" & forms.[order form].[CRN] 'still might have to adjust
quotes
Me.filterOn=true
else: me.filteron=false
End If
end sub
make sure to turn filter on load to yes
"mick" wrote:

I have a "customers input form" for entering name, address, ref no.,
etc.
I have an "order form" with a text box into which can be manually
entered a customer reference number when needed. Next to the box is a
button that when activated opens the "customers input form" displaying
the customer details.
The macro for the button is:
OpenForm
form name, customers input
where condition, ="[CRN]=" & [CRN]

This works fine, except when the button is activated and there is
nothing in the text box, there is then a syntax error and the macro has
to be stopped manually.

Question is; what do I need to add to the macro to prevent the error
happening when the text box is empty and the button is activated?

Thanks.

--
mick


.

  #3  
Old June 3rd, 2010, 09:24 PM posted to microsoft.public.access.gettingstarted
KenSheridan via AccessMonster.com
external usenet poster
 
Posts: 1,610
Default macro help

Rather than using a macro put the following code in the button's Click event
procedu

Const MESSAGETEXT = "No customer reference number entered."
Const FORMNAME = "Customers Input"

Dim strCriteria As String

strCriteria = "CRN = " & Me.CRN

If Not IsNull(Me.CRN) Then
DoCmd.OpenForm FORMNAME, _
WhereCondition:=strCriteria
Else
MsgBox MESSAGETEXT, vbExclamation, "Invalid Operation"
End If

If you are not familiar with entering code in event procedures this is how
it's done:

1. Select the control and open its properties sheet if it's not already open.


2. Select the On Click event property and select the 'build' button (the one
on the right with 3 dots).

3. Select Code Builder in the dialogue and click OK. This step won't be
necessary if you've set up Access to use event procedures by default.

4. The VBA editor window will open at the Click event procedure with the
first and last lines already in place. Enter or paste in the code as new
lines between these.

Ken Sheridan
Stafford, England

mick wrote:
I have a "customers input form" for entering name, address, ref no.,
etc.
I have an "order form" with a text box into which can be manually
entered a customer reference number when needed. Next to the box is a
button that when activated opens the "customers input form" displaying
the customer details.
The macro for the button is:
OpenForm
form name, customers input
where condition, ="[CRN]=" & [CRN]

This works fine, except when the button is activated and there is
nothing in the text box, there is then a syntax error and the macro has
to be stopped manually.

Question is; what do I need to add to the macro to prevent the error
happening when the text box is empty and the button is activated?

Thanks.


--
Message posted via AccessMonster.com
http://www.accessmonster.com/Uwe/For...arted/201006/1

  #4  
Old June 4th, 2010, 11:07 PM posted to microsoft.public.access.gettingstarted
mick
external usenet poster
 
Posts: 2
Default macro help

Rather than using a macro put the following code in the button's Click event
procedu

Const MESSAGETEXT = "No customer reference number entered."
Const FORMNAME = "Customers Input"

Dim strCriteria As String

strCriteria = "CRN = " & Me.CRN

If Not IsNull(Me.CRN) Then
DoCmd.OpenForm FORMNAME, _
WhereCondition:=strCriteria
Else
MsgBox MESSAGETEXT, vbExclamation, "Invalid Operation"
End If

If you are not familiar with entering code in event procedures this is how
it's done:

1. Select the control and open its properties sheet if it's not already
open.


2. Select the On Click event property and select the 'build' button (the one
on the right with 3 dots).

3. Select Code Builder in the dialogue and click OK. This step won't be
necessary if you've set up Access to use event procedures by default.

4. The VBA editor window will open at the Click event procedure with the
first and last lines already in place. Enter or paste in the code as new
lines between these.

Ken Sheridan
Stafford, England

mick wrote:
I have a "customers input form" for entering name, address, ref no.,
etc.
I have an "order form" with a text box into which can be manually
entered a customer reference number when needed. Next to the box is a
button that when activated opens the "customers input form" displaying
the customer details.
The macro for the button is:
OpenForm
form name, customers input
where condition, ="[CRN]=" & [CRN]

This works fine, except when the button is activated and there is
nothing in the text box, there is then a syntax error and the macro has
to be stopped manually.

Question is; what do I need to add to the macro to prevent the error
happening when the text box is empty and the button is activated?

Thanks.


Many thanks Ken, worked a treat.

--
mick


 




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump


All times are GMT +1. The time now is 12:58 PM.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 OfficeFrustration.
The comments are property of their posters.