Message Yes/No to proceede to next record or close form

K

Ktowner

I posted in several weeks ago with a code question. I would like Access to
prompt me to enter a new record or close my access form when a submit butten
is hit. I got the following code from a reply and tied it to my submit
button on my form.

Dim strMsg As String
Dim vbResponse

strMsg = "Would You Like To Enter Another Record?"
vbResponse = MsgBox(strMsg, vbYesNo + vbDefaultButton2 + vbQuestion, _
"Create New Record?")
If vbResponse = vbYes Then
DoCmd.GoToRecord , , acNewRec
Else

DoCmd.Close acForm, "Area Shop Workload New 350"

I thought it was working at first but later found that although it go to a
new record, it does not go to the 0 tab stop. I have to click on the first
field. Also should I see the message “Create New Record?†at some point?

Is this code working properly, should I have to point and click the field?

Thanks

Don K.
 
K

Klatuu

I don't see an End If in your code.
The focus will not automaticaly be set to any position. You will have to do
it yourself. In the example below, it assumes the name of the control with
the 0 tab stop is txtFirstPlace

If MsgBox("Would You Like To Enter Another Record?", _
vbYesNo + vbDefaultButton2 + vbQuestion, _
"Create New Record?") = vbYes Then
DoCmd.GoToRecord , , acNewRec
Me.txtFirstPlace.SetFocus
Else
DoCmd.Close acForm, "Area Shop Workload New 350"
End If
 
K

Ktowner

I have edited my code as you suggested, see below,

Private Sub Enter_Next_350_or_354_Click()
Dim strMsg As String
Dim vbResponse

If MsgBox("Would You Like To Enter Another Record?", _
vbYesNo + vbDefaultButton2 + vbQuestion, _
"Create New Record?") = vbYes Then
DoCmd.GoToRecord , , acNewRec
Me.Dot Number.SetFocus
Else
DoCmd.Close acForm, "Area Shop Workload New 350"
End If

End Sub

The name of my 0 tab stop control is Dot Number

Now when hitting the submit key, I get a Compile error: 461
method or data member not found.

Me.Dot Number.SetFocus
The .Dot in the code line above is highlited.

Thanks again for the help

Don K.
 
K

Klatuu

It is because you have a space in the name. Try:

Me.[Dot Number].SetFocus

Never put spaces in names.
 
K

Ktowner

Thank you Klatuu

It works like a champ.

One final question. Working with the SQL code language is new to me. It
reminds me a little of the "basic" language that was around in the early
80's. My first computer was an IBM PC jr. It came with a book full of
simple "basic" programs that were typed in line by line and when executed a
simple program would run.

Can you recommend some good SQL code language reference material for a
novice like myself?

Thanks Again

Don K.

Klatuu said:
It is because you have a space in the name. Try:

Me.[Dot Number].SetFocus

Never put spaces in names.

--
Dave Hargis, Microsoft Access MVP


Ktowner said:
I have edited my code as you suggested, see below,

Private Sub Enter_Next_350_or_354_Click()
Dim strMsg As String
Dim vbResponse

If MsgBox("Would You Like To Enter Another Record?", _
vbYesNo + vbDefaultButton2 + vbQuestion, _
"Create New Record?") = vbYes Then
DoCmd.GoToRecord , , acNewRec
Me.Dot Number.SetFocus
Else
DoCmd.Close acForm, "Area Shop Workload New 350"
End If

End Sub

The name of my 0 tab stop control is Dot Number

Now when hitting the submit key, I get a Compile error: 461
method or data member not found.

Me.Dot Number.SetFocus
The .Dot in the code line above is highlited.

Thanks again for the help

Don K.
 
D

Douglas J. Steele

What Dave was showing you isn't SQL, it's VBA (Visual Basic for
Applications, so it's small wonder it reminds you of the Basic language that
came with IBM PCs!) SQL (Structured Query Language) is a very different
thing.

For a list of web sites that have lists of good reference material, see what
Jeff Conrad has at
http://www.accessmvp.com/JConrad/accessjunkie/resources.html#Books

--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)


Ktowner said:
Thank you Klatuu

It works like a champ.

One final question. Working with the SQL code language is new to me. It
reminds me a little of the "basic" language that was around in the early
80's. My first computer was an IBM PC jr. It came with a book full of
simple "basic" programs that were typed in line by line and when executed
a
simple program would run.

Can you recommend some good SQL code language reference material for a
novice like myself?

Thanks Again

Don K.

Klatuu said:
It is because you have a space in the name. Try:

Me.[Dot Number].SetFocus

Never put spaces in names.

--
Dave Hargis, Microsoft Access MVP


Ktowner said:
I have edited my code as you suggested, see below,

Private Sub Enter_Next_350_or_354_Click()
Dim strMsg As String
Dim vbResponse

If MsgBox("Would You Like To Enter Another Record?", _
vbYesNo + vbDefaultButton2 + vbQuestion, _
"Create New Record?") = vbYes Then
DoCmd.GoToRecord , , acNewRec
Me.Dot Number.SetFocus
Else
DoCmd.Close acForm, "Area Shop Workload New 350"
End If

End Sub

The name of my 0 tab stop control is Dot Number

Now when hitting the submit key, I get a Compile error: 461
method or data member not found.

Me.Dot Number.SetFocus
The .Dot in the code line above is highlited.

Thanks again for the help

Don K.

:

I don't see an End If in your code.
The focus will not automaticaly be set to any position. You will
have to do
it yourself. In the example below, it assumes the name of the
control with
the 0 tab stop is txtFirstPlace

If MsgBox("Would You Like To Enter Another Record?", _
vbYesNo + vbDefaultButton2 + vbQuestion, _
"Create New Record?") = vbYes Then
DoCmd.GoToRecord , , acNewRec
Me.txtFirstPlace.SetFocus
Else
DoCmd.Close acForm, "Area Shop Workload New 350"
End If

--
Dave Hargis, Microsoft Access MVP


:

I posted in several weeks ago with a code question. I would like
Access to
prompt me to enter a new record or close my access form when a
submit butten
is hit. I got the following code from a reply and tied it to my
submit
button on my form.

Dim strMsg As String
Dim vbResponse

strMsg = "Would You Like To Enter Another Record?"
vbResponse = MsgBox(strMsg, vbYesNo + vbDefaultButton2 +
vbQuestion, _
"Create New Record?")
If vbResponse = vbYes Then
DoCmd.GoToRecord , , acNewRec
Else

DoCmd.Close acForm, "Area Shop Workload New 350"

I thought it was working at first but later found that although it
go to a
new record, it does not go to the 0 tab stop. I have to click on
the first
field. Also should I see the message "Create New Record?" at some
point?

Is this code working properly, should I have to point and click the
field?

Thanks

Don K.
 

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

Top