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  dBforums > PC based Database Applications > Microsoft Access > add New record

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 12-09-03, 15:17
badr badr is offline
Registered User
 
Join Date: Dec 2003
Location: Toronto
Posts: 11
Question add New record

I'm using a form to add a new record to a table. the table has a autonumber as PK. I have a button that when clicked validate the entry from form fields to table fields. The problem is it would accept to add the new record the first time, I have to click a second time to make it go through. And this because the autonumber had to jump to a new number first.
Can please tell if there is a way to achieve that without having to click twice( just to let you know I'm using this code in the button Sub:
If Not Me.NewRecord Then
RunCommand acCmdRecordsGoToNew
End If

On Error GoTo ErrNew
DoCmd****nCommand acCmdRecordsGoToNew
Exit Sub
ErrNew:
Select Case Err
Case 2046
'Command not available
MsgBox "You cannot add a record at this time.", vbInformation, "Not Available"
Case Else
MsgBox Err.Number & ":-" & vbCrLf & Err.Description
End Select

so the first click always dispalys "You cannot add a record at this time.", message.

Another thing as long the form is open I can perform the adding with no problem(only on click on the button) the problem happens only the first time I open the form

thanks
Reply With Quote
  #2 (permalink)  
Old 12-09-03, 15:43
jmrSudbury jmrSudbury is offline
Registered User
 
Join Date: Oct 2003
Location: Canada
Posts: 573
I don't know why you have it going to a new record twice. That could be your error. I use the following:

If DoubleCheck = -1 Then 'subroutine that checks for nulls
If Me.Dirty Then DoCmd****nCommand acCmdSaveRecord
If SaveInfo <> "" Then
If Me.DataEntry = 0 Then Me.DataEntry = -1
DoCmd.GoToRecord , , acNewRec
End If
End If
Reply With Quote
  #3 (permalink)  
Old 12-09-03, 21:24
bluejamul bluejamul is offline
Registered User
 
Join Date: Dec 2003
Posts: 16
I don't know which version of Access you are using (97 for me), but I use this. I am assuming you are using a bound form. This will add the record and make it current.

'do your checking
' open a recordset based on your table or query

With rst
.AddNew
' write your data
.Update
Move 0, .LastModified
Me.Bookmark=.Bookmark
End With
Reply With Quote
Reply

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

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On