newby code question

  • Thread starter Thread starter steve goodrich
  • Start date Start date
S

steve goodrich

I want to put a command button on my form that will perform the following

Go to a new record
Set the focus to my first field which is "Date From"
Display a message "Booking Confirmed"

I have typed in the following in the buttons on click event

DoCmd.GoToRecord , , acNewRec
Me.DATE_FROM.SetFocus
msgbox "Booking Confirmed"

One of my fields"Auth By" has a validation rule applied to it which is - IS
NOT NULL then the validation text message

If the validation rule is not broken then clicking the button carries out
the above code displaying my message and opening a new record with the
focus on my "Date From" field - which is what I want

If the validation rule is broken I.E there is no value in the "auth By"
field then I get the following error message

Run time error 2105
You can't go to the specified record
You may be at the end of a record set

How do I stop the error message. All I want to see is the Validation error
message so the user can complete the "Auth By" field

Any help would be appreciated

Steve
 
Hi goodrich,

There probably are other ways to do it, but why not just put your
'validation rule' in your vba code as part of the on_click event of your
button. It might look something like this:

Private Sub MyButton_Click ()
If IsNull [Auth By] Then
MsgBox "You must complete the "Auth By" field to proceed"
Me.[Auth By].setfocus
Exit Sub
Else
DoCmd.GoToRecord , , acNewRec
Me.DATE_FROM.SetFocus
msgbox "Booking Confirmed"

End Sub

I think that should work.

Hope that helps,
CW
 
I'm assumming your code works fine other than when the validation rule works.
Also, when referring to a control who's name has a space in it, I always use
the [Name here] .

To refer to the [Auth by] field, I'd probably use Me![Auth by] instead of
[Auth by] alone (or, maybe you have to use Me.[Auth by]...). The [Auth by]
by itself will probably work, though, but I mention it just in case.

Finally, I don't know why, but I try to avoid field names with spaces in them.

CW

Cheese_whiz said:
Hi goodrich,

There probably are other ways to do it, but why not just put your
'validation rule' in your vba code as part of the on_click event of your
button. It might look something like this:

Private Sub MyButton_Click ()
If IsNull [Auth By] Then
MsgBox "You must complete the "Auth By" field to proceed"
Me.[Auth By].setfocus
Exit Sub
Else
DoCmd.GoToRecord , , acNewRec
Me.DATE_FROM.SetFocus
msgbox "Booking Confirmed"

End Sub

I think that should work.

Hope that helps,
CW

steve goodrich said:
I want to put a command button on my form that will perform the following

Go to a new record
Set the focus to my first field which is "Date From"
Display a message "Booking Confirmed"

I have typed in the following in the buttons on click event

DoCmd.GoToRecord , , acNewRec
Me.DATE_FROM.SetFocus
msgbox "Booking Confirmed"

One of my fields"Auth By" has a validation rule applied to it which is - IS
NOT NULL then the validation text message

If the validation rule is not broken then clicking the button carries out
the above code displaying my message and opening a new record with the
focus on my "Date From" field - which is what I want

If the validation rule is broken I.E there is no value in the "auth By"
field then I get the following error message

Run time error 2105
You can't go to the specified record
You may be at the end of a record set

How do I stop the error message. All I want to see is the Validation error
message so the user can complete the "Auth By" field

Any help would be appreciated

Steve
 
So, it might be better with this:

If IsNull(Me![Auth by]) Then or
If (IsNull(Me.[Auth by]) Then

I think the ! is prefered when it can be used because the "." requires some
additional work by Access to resolve.

instead of like I wrote it

Darn, no more posting before I wake up.

From one newb to another, I am
CW

Cheese_whiz said:
I'm assumming your code works fine other than when the validation rule works.
Also, when referring to a control who's name has a space in it, I always use
the [Name here] .

To refer to the [Auth by] field, I'd probably use Me![Auth by] instead of
[Auth by] alone (or, maybe you have to use Me.[Auth by]...). The [Auth by]
by itself will probably work, though, but I mention it just in case.

Finally, I don't know why, but I try to avoid field names with spaces in them.

CW

Cheese_whiz said:
Hi goodrich,

There probably are other ways to do it, but why not just put your
'validation rule' in your vba code as part of the on_click event of your
button. It might look something like this:

Private Sub MyButton_Click ()
If IsNull [Auth By] Then
MsgBox "You must complete the "Auth By" field to proceed"
Me.[Auth By].setfocus
Exit Sub
Else
DoCmd.GoToRecord , , acNewRec
Me.DATE_FROM.SetFocus
msgbox "Booking Confirmed"

End Sub

I think that should work.

Hope that helps,
CW

steve goodrich said:
I want to put a command button on my form that will perform the following

Go to a new record
Set the focus to my first field which is "Date From"
Display a message "Booking Confirmed"

I have typed in the following in the buttons on click event

DoCmd.GoToRecord , , acNewRec
Me.DATE_FROM.SetFocus
msgbox "Booking Confirmed"

One of my fields"Auth By" has a validation rule applied to it which is - IS
NOT NULL then the validation text message

If the validation rule is not broken then clicking the button carries out
the above code displaying my message and opening a new record with the
focus on my "Date From" field - which is what I want

If the validation rule is broken I.E there is no value in the "auth By"
field then I get the following error message

Run time error 2105
You can't go to the specified record
You may be at the end of a record set

How do I stop the error message. All I want to see is the Validation error
message so the user can complete the "Auth By" field

Any help would be appreciated

Steve
 
Thanks for your help, got it working
Cheese_whiz said:
So, it might be better with this:

If IsNull(Me![Auth by]) Then or
If (IsNull(Me.[Auth by]) Then

I think the ! is prefered when it can be used because the "." requires
some
additional work by Access to resolve.

instead of like I wrote it

Darn, no more posting before I wake up.

From one newb to another, I am
CW

Cheese_whiz said:
I'm assumming your code works fine other than when the validation rule
works.
Also, when referring to a control who's name has a space in it, I always
use
the [Name here] .

To refer to the [Auth by] field, I'd probably use Me![Auth by] instead of
[Auth by] alone (or, maybe you have to use Me.[Auth by]...). The [Auth
by]
by itself will probably work, though, but I mention it just in case.

Finally, I don't know why, but I try to avoid field names with spaces in
them.

CW

Cheese_whiz said:
Hi goodrich,

There probably are other ways to do it, but why not just put your
'validation rule' in your vba code as part of the on_click event of
your
button. It might look something like this:

Private Sub MyButton_Click ()
If IsNull [Auth By] Then
MsgBox "You must complete the "Auth By" field to proceed"
Me.[Auth By].setfocus
Exit Sub
Else
DoCmd.GoToRecord , , acNewRec
Me.DATE_FROM.SetFocus
msgbox "Booking Confirmed"

End Sub

I think that should work.

Hope that helps,
CW

:

I want to put a command button on my form that will perform the
following

Go to a new record
Set the focus to my first field which is "Date From"
Display a message "Booking Confirmed"

I have typed in the following in the buttons on click event

DoCmd.GoToRecord , , acNewRec
Me.DATE_FROM.SetFocus
msgbox "Booking Confirmed"

One of my fields"Auth By" has a validation rule applied to it which
is - IS
NOT NULL then the validation text message

If the validation rule is not broken then clicking the button carries
out
the above code displaying my message and opening a new record with
the
focus on my "Date From" field - which is what I want

If the validation rule is broken I.E there is no value in the "auth
By"
field then I get the following error message

Run time error 2105
You can't go to the specified record
You may be at the end of a record set

How do I stop the error message. All I want to see is the Validation
error
message so the user can complete the "Auth By" field

Any help would be appreciated

Steve
 
Check this article for more information about using the exclamation mark
(bang) or the dot:
http://doc.advisor.com/doc/05352
I think the dot syntax actually runs faster, but probably not enough to
notice the difference in most cases.
Two practical advantages to using the dot are that the Intellisense menu
lets you choose from a list, and spelling etc. errors are resolved when the
code is compiled.
If spaces are avoided in field names, brackets aren't necessary in many
cases (provided the field name isn't also the name of a property such as
Date).

Cheese_whiz said:
So, it might be better with this:

If IsNull(Me![Auth by]) Then or
If (IsNull(Me.[Auth by]) Then

I think the ! is prefered when it can be used because the "." requires
some
additional work by Access to resolve.

instead of like I wrote it

Darn, no more posting before I wake up.

From one newb to another, I am
CW

Cheese_whiz said:
I'm assumming your code works fine other than when the validation rule
works.
Also, when referring to a control who's name has a space in it, I always
use
the [Name here] .

To refer to the [Auth by] field, I'd probably use Me![Auth by] instead of
[Auth by] alone (or, maybe you have to use Me.[Auth by]...). The [Auth
by]
by itself will probably work, though, but I mention it just in case.

Finally, I don't know why, but I try to avoid field names with spaces in
them.

CW

Cheese_whiz said:
Hi goodrich,

There probably are other ways to do it, but why not just put your
'validation rule' in your vba code as part of the on_click event of
your
button. It might look something like this:

Private Sub MyButton_Click ()
If IsNull [Auth By] Then
MsgBox "You must complete the "Auth By" field to proceed"
Me.[Auth By].setfocus
Exit Sub
Else
DoCmd.GoToRecord , , acNewRec
Me.DATE_FROM.SetFocus
msgbox "Booking Confirmed"

End Sub

I think that should work.

Hope that helps,
CW

:

I want to put a command button on my form that will perform the
following

Go to a new record
Set the focus to my first field which is "Date From"
Display a message "Booking Confirmed"

I have typed in the following in the buttons on click event

DoCmd.GoToRecord , , acNewRec
Me.DATE_FROM.SetFocus
msgbox "Booking Confirmed"

One of my fields"Auth By" has a validation rule applied to it which
is - IS
NOT NULL then the validation text message

If the validation rule is not broken then clicking the button carries
out
the above code displaying my message and opening a new record with
the
focus on my "Date From" field - which is what I want

If the validation rule is broken I.E there is no value in the "auth
By"
field then I get the following error message

Run time error 2105
You can't go to the specified record
You may be at the end of a record set

How do I stop the error message. All I want to see is the Validation
error
message so the user can complete the "Auth By" field

Any help would be appreciated

Steve
 
Thanks Bruce. That's helpful.

Steve,
Glad you got it to work.

CW

BruceM said:
Check this article for more information about using the exclamation mark
(bang) or the dot:
http://doc.advisor.com/doc/05352
I think the dot syntax actually runs faster, but probably not enough to
notice the difference in most cases.
Two practical advantages to using the dot are that the Intellisense menu
lets you choose from a list, and spelling etc. errors are resolved when the
code is compiled.
If spaces are avoided in field names, brackets aren't necessary in many
cases (provided the field name isn't also the name of a property such as
Date).

Cheese_whiz said:
So, it might be better with this:

If IsNull(Me![Auth by]) Then or
If (IsNull(Me.[Auth by]) Then

I think the ! is prefered when it can be used because the "." requires
some
additional work by Access to resolve.

instead of like I wrote it

Darn, no more posting before I wake up.

From one newb to another, I am
CW

Cheese_whiz said:
I'm assumming your code works fine other than when the validation rule
works.
Also, when referring to a control who's name has a space in it, I always
use
the [Name here] .

To refer to the [Auth by] field, I'd probably use Me![Auth by] instead of
[Auth by] alone (or, maybe you have to use Me.[Auth by]...). The [Auth
by]
by itself will probably work, though, but I mention it just in case.

Finally, I don't know why, but I try to avoid field names with spaces in
them.

CW

:

Hi goodrich,

There probably are other ways to do it, but why not just put your
'validation rule' in your vba code as part of the on_click event of
your
button. It might look something like this:

Private Sub MyButton_Click ()
If IsNull [Auth By] Then
MsgBox "You must complete the "Auth By" field to proceed"
Me.[Auth By].setfocus
Exit Sub
Else
DoCmd.GoToRecord , , acNewRec
Me.DATE_FROM.SetFocus
msgbox "Booking Confirmed"

End Sub

I think that should work.

Hope that helps,
CW

:

I want to put a command button on my form that will perform the
following

Go to a new record
Set the focus to my first field which is "Date From"
Display a message "Booking Confirmed"

I have typed in the following in the buttons on click event

DoCmd.GoToRecord , , acNewRec
Me.DATE_FROM.SetFocus
msgbox "Booking Confirmed"

One of my fields"Auth By" has a validation rule applied to it which
is - IS
NOT NULL then the validation text message

If the validation rule is not broken then clicking the button carries
out
the above code displaying my message and opening a new record with
the
focus on my "Date From" field - which is what I want

If the validation rule is broken I.E there is no value in the "auth
By"
field then I get the following error message

Run time error 2105
You can't go to the specified record
You may be at the end of a record set

How do I stop the error message. All I want to see is the Validation
error
message so the user can complete the "Auth By" field

Any help would be appreciated

Steve
 

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

Paste append error message 4
Validation Question 2
Validation rule problem 7
Validation Rule 2
Error handler help 4
VBA code to select website drop down opion 0
Email Bounce Error 3
Validation Rules 2

Back
Top