By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,504 Members | 1,212 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,504 IT Pros & Developers. It's quick & easy.

new record

P: n/a
I was using a box to check for an existing record and if it was not
found I would add a record.
This was simple except after creating the record I was updating
the main record number box and it errors out.

Private Sub Text181_AfterUpdate()
Dim rst As Recordset
Dim response As Integer
Dim val As String
Set rst = Me.RecordsetClone
If Not IsNull(Me.Text181) Then
rst.FindFirst "[fldMR] = """ & Text181.Value & """"
If rst.NoMatch Then
rst.Close
response = MsgBox("this record number does not exist.Do you want
to add it", vbYesNoCancel)
If response = vbYes Then
val = Me.Text181.Value
DoCmd.GoToRecord , , acNewRec
Me.fldMR.Value = val <=== if this is rem out it works
Me.fldMR.SetFocus
Else
' stay on this field
End If
Else
Me.Bookmark = rst.Bookmark
rst.Close
End If
End If
End Sub
I can't figure out why copying the value to the field will error out
but when you go back in the record has been created.

does anyone know how to get around this?

thanks big time for any help

Jerry

Jan 10 '06 #1
Share this Question
Share on Google+
2 Replies


P: n/a
sparks wrote:
I was using a box to check for an existing record and if it was not
found I would add a record.
This was simple except after creating the record I was updating
the main record number box and it errors out.

Private Sub Text181_AfterUpdate()
Dim rst As Recordset
Dim response As Integer
Dim val As String
Set rst = Me.RecordsetClone
If Not IsNull(Me.Text181) Then
rst.FindFirst "[fldMR] = """ & Text181.Value & """"
If rst.NoMatch Then
rst.Close
response = MsgBox("this record number does not exist.Do you want
to add it", vbYesNoCancel)
If response = vbYes Then
val = Me.Text181.Value
DoCmd.GoToRecord , , acNewRec
Me.fldMR.Value = val <=== if this is rem out it works
Me.fldMR.SetFocus
Else
' stay on this field
End If
Else
Me.Bookmark = rst.Bookmark
rst.Close
End If
End If
End Sub
I can't figure out why copying the value to the field will error out
but when you go back in the record has been created.

does anyone know how to get around this?

thanks big time for any help

Jerry

Well, since you have a recordset open...

I create a table called Table1; 3 fields; ID (autonumber), F1 (text),
and F2 (YesNo). I have the following code in the AfterUpdate event for F2.

Private Sub F2_AfterUpdate()
If Me.F2 Then
'F2 was checked
Dim rst As Recordset
Set rst = Me.RecordsetClone
rst.AddNew
rst!F1 = "Added New"
rst.Update
rst.Bookmark = rst.LastModified
Me.Bookmark = rst.Bookmark
End If
End Sub

This code seems to work OK.
Jan 10 '06 #2

P: n/a
Ok think I got it I did an .add in the recordset and update and it
seems to work like I wanted it to.

Jerry

On Tue, 10 Jan 2006 17:57:44 GMT, sparks <js******@swbell.net> wrote:
I was using a box to check for an existing record and if it was not
found I would add a record.
This was simple except after creating the record I was updating
the main record number box and it errors out.

Private Sub Text181_AfterUpdate()
Dim rst As Recordset
Dim response As Integer
Dim val As String
Set rst = Me.RecordsetClone
If Not IsNull(Me.Text181) Then
rst.FindFirst "[fldMR] = """ & Text181.Value & """"
If rst.NoMatch Then
rst.Close
response = MsgBox("this record number does not exist.Do you want
to add it", vbYesNoCancel)
If response = vbYes Then
val = Me.Text181.Value
DoCmd.GoToRecord , , acNewRec
Me.fldMR.Value = val <=== if this is rem out it works
Me.fldMR.SetFocus
Else
' stay on this field
End If
Else
Me.Bookmark = rst.Bookmark
rst.Close
End If
End If
End Sub
I can't figure out why copying the value to the field will error out
but when you go back in the record has been created.

does anyone know how to get around this?

thanks big time for any help

Jerry


Jan 10 '06 #3

This discussion thread is closed

Replies have been disabled for this discussion.