Connecting Tech Pros Worldwide Forums | Help | Site Map

Can't use the GoToRecord Action in Design View

Tim Hunter
Guest
 
Posts: n/a
#1: Dec 4 '06
Hi,
I am running Access 2003 with WinXP Professional.
I am not new to Access but I find myself more and more confused by the
messages I receive. I am trying to add a record to a table via a form
button: "ADD" Command. I am getting the message and I am not in design
mode.
Here is my code. The application itself is a little odd but the adding
of a record is something i have done many times before and I can't seem
to understand what it is that i am doing wrong..

Private Sub cmdAdd_Click()

On Error GoTo cmdAddClickErr
' Customer Maintenance
strRememberMe = Forms![CustomerMaintenance].Bookmark
strIndex = Forms![CustomerMaintenance].txtIndex
Me.cmdReturn.SetFocus
Me!cmdAdd.Enabled = False
Me!cmdUpdate.Enabled = False
Me!cmdDelete.Enabled = False
Me.AllowAdditions = True
DoCmd.GoToRecord , , acNewRec

Me.Title.Locked = False
Me.FirstName.Locked = False
Me.LastName.Locked = False
Me.Address.Locked = False
Me.City.Locked = False
Me.State.Locked = False
Me.Zip.Locked = False
Me.Phone.Locked = False
Me.Birthday.Locked = False
Me.Anniversary.Locked = False
If IsEmail() Then
Me.Email = strIndex
Else
Me.LastName = strLastName
Me.Address = strAddress
Me.LastName.Locked = True
Me.Address.Locked = True
End If

Me.Title.SetFocus
Exit Sub

cmdAddClickErr:
If Err <0 Then
MsgBox Error$, vbCritical
End If
Resume Next
End Sub

TIA
Tim


*** Sent via Developersdex http://www.developersdex.com ***

Allen Browne
Guest
 
Posts: n/a
#2: Dec 5 '06

re: Can't use the GoToRecord Action in Design View


Suggestions, Tim

1. Temporarily comment out the error handler, by adding a single quote to
ths start of the first line, i.e.:
'On Error GoTo cmdAddClickErr
You can then see which line is causing the error, which will help you
understand the cause.

2. Explicitly save the record before attempting to go to the new record, or
remember the bookmark. The bookmark is invalid at a new record, so you need
a variant. Perhaps:
Dim varRememberMe As Variant
If Me.Dirty Then Me.Dirty = False
If Me.NewRecord Then
varRememberMe = Null
Else
RunCommand acCmdRecordsGotoNew
varRememberMe = Me.Bookmark
End If

3. Your code is disabling cmdAdd, but the button probably has the focus
(since this is its Click event.) You will need to SetFocus to something else
before you can disable it:
Me.[SomeOtherControl].SetFocus

4. Use Option Explicit (top of all modules.) It makes a world of difference
to catching bugs.

If the problem persists after that, post back for further instructions on
how to disable Name AutoCorrect, compact, decompile, and check references.

--
Allen Browne - Microsoft MVP. Perth, Western Australia
Tips for Access users - http://allenbrowne.com/tips.html
Reply to group, rather than allenbrowne at mvps dot org.

"Tim Hunter" <thunter@rochester.rr.comwrote in message
news:45749239$0$3578$815e3792@news.qwest.net...
Quote:
Hi,
I am running Access 2003 with WinXP Professional.
I am not new to Access but I find myself more and more confused by the
messages I receive. I am trying to add a record to a table via a form
button: "ADD" Command. I am getting the message and I am not in design
mode.
Here is my code. The application itself is a little odd but the adding
of a record is something i have done many times before and I can't seem
to understand what it is that i am doing wrong..
>
Private Sub cmdAdd_Click()
>
On Error GoTo cmdAddClickErr
' Customer Maintenance
strRememberMe = Forms![CustomerMaintenance].Bookmark
strIndex = Forms![CustomerMaintenance].txtIndex
Me.cmdReturn.SetFocus
Me!cmdAdd.Enabled = False
Me!cmdUpdate.Enabled = False
Me!cmdDelete.Enabled = False
Me.AllowAdditions = True
DoCmd.GoToRecord , , acNewRec
>
Me.Title.Locked = False
Me.FirstName.Locked = False
Me.LastName.Locked = False
Me.Address.Locked = False
Me.City.Locked = False
Me.State.Locked = False
Me.Zip.Locked = False
Me.Phone.Locked = False
Me.Birthday.Locked = False
Me.Anniversary.Locked = False
If IsEmail() Then
Me.Email = strIndex
Else
Me.LastName = strLastName
Me.Address = strAddress
Me.LastName.Locked = True
Me.Address.Locked = True
End If
>
Me.Title.SetFocus
Exit Sub
>
cmdAddClickErr:
If Err <0 Then
MsgBox Error$, vbCritical
End If
Resume Next
End Sub

Closed Thread