NotInList Event does not return to original record

K

khel

I have the following written to the NotInList event to add a new name to a
combo box in a form:

Option Compare Database
Option Explicit

Private Sub Combo16_NotInList(NewData As String, Response As Integer)
Dim strMsg As String
strMsg = "Add new field name?"
If MsgBox(strMsg, vbYesNo) = vbYes Then
'open form and pass NewData
DoCmd.OpenForm "frmField Info", , , , acFormAdd, acDialog, NewData
Response = acDataErrAdded 'tell access to requery combo

Else
'cancel even and undo typing
Response = acDataErrContinue
Me.Undo

End If
End Sub

However, after I return from the referenced form "frmField Info" to the
original form I am no longer on the same record. I have advanced to the next
record with only the updated field on the preceding added record. Any
suggestions on how to return to the correct record? Thanks!
 
S

sierra

Użytkownik "khel said:
I have the following written to the NotInList event to add a new name to a
combo box in a form:

Option Compare Database
Option Explicit

Private Sub Combo16_NotInList(NewData As String, Response As Integer)
Dim strMsg As String
strMsg = "Add new field name?"
If MsgBox(strMsg, vbYesNo) = vbYes Then
'open form and pass NewData
DoCmd.OpenForm "frmField Info", , , , acFormAdd, acDialog, NewData
Response = acDataErrAdded 'tell access to requery combo

Else
'cancel even and undo typing
Response = acDataErrContinue
Me.Undo

End If
End Sub

However, after I return from the referenced form "frmField Info" to the
original form I am no longer on the same record. I have advanced to the
next
record with only the updated field on the preceding added record. Any
suggestions on how to return to the correct record? Thanks!
 
K

khel

I thought acFormAdd was to add data to the referenced form to fill the info
in the combo box, not the "base form." I have a "base form," frmMonthly
Purchaser Price Info which includes a combo box, Combo16. This combo box has
a notinlist event that is listed below. The form, frmField Info, is opened
with this event and new data is listed to populate the combo box on
frmMonthly Purchaser. However, once returning to the "base form," frmMonthly
Purchaser I am no longer on the record I was adding, I have advanced one
record with only the information that I added from frmField Info on the
preceding record. I would like to return to the original record that I was
attempting to add on the base form, before I chose the notinlist event option
of adding data to my combo box. I don't know if I have further confused the
situation with my explanation. Thanks for your help. K
 
R

Richard

khel


He is some code from microsoft's "house hold inventory" template they use
the NotInList function in the double click event.


Private Sub CategoryID_DblClick(Cancel As Integer)
On Error GoTo Err_CategoryID_DblClick
Dim lngCategoryID As Long

If IsNull(Me![CategoryID]) Then
Me![CategoryID].Text = ""
Else
lngCategoryID = Me![CategoryID]
Me![CategoryID] = Null
End If
DoCmd.OpenForm "Categories", , , , , acDialog, "GotoNew"
Me![CategoryID].Requery
If lngCategoryID <> 0 Then Me![CategoryID] = lngCategoryID

Exit_CategoryID_DblClick:
Exit Sub

Err_CategoryID_DblClick:
MsgBox Err.Description
Resume Exit_CategoryID_DblClick
End Sub


notice no use of the acformadd ? take a look at this line.

DoCmd.OpenForm "Categories", , , , , acDialog, "GotoNew"

You may be able to use this in your project.


HTH
Richard
 
K

khel

Thanks for all your help. I haven't tried the latest code that you sent,
but I'm beginning to wonder if it is a problem with my combo box. I have
always used the cursor to select the correct data in the combo box and then
selected the next field on the form with the cursor. If I use enter or tab
it goes to the next record on the form. How do I correct that? Again,
thanks for your suggestions! K

Richard said:
khel


He is some code from microsoft's "house hold inventory" template they use
the NotInList function in the double click event.


Private Sub CategoryID_DblClick(Cancel As Integer)
On Error GoTo Err_CategoryID_DblClick
Dim lngCategoryID As Long

If IsNull(Me![CategoryID]) Then
Me![CategoryID].Text = ""
Else
lngCategoryID = Me![CategoryID]
Me![CategoryID] = Null
End If
DoCmd.OpenForm "Categories", , , , , acDialog, "GotoNew"
Me![CategoryID].Requery
If lngCategoryID <> 0 Then Me![CategoryID] = lngCategoryID

Exit_CategoryID_DblClick:
Exit Sub

Err_CategoryID_DblClick:
MsgBox Err.Description
Resume Exit_CategoryID_DblClick
End Sub


notice no use of the acformadd ? take a look at this line.

DoCmd.OpenForm "Categories", , , , , acDialog, "GotoNew"

You may be able to use this in your project.


HTH
Richard



Richard said:
Khel

This is where I found the info on "acformadd"
http://www.blueclaw-db.com/docmd_openform_example.htm
About half way down the page.

Microsoft has a similar explaination in there kb. If it was me I would try
and comment out that line and see what happens.

Richard
 
R

Richard

Look in tools >> options >>> keyboard

Richard

khel said:
Thanks for all your help. I haven't tried the latest code that you sent,
but I'm beginning to wonder if it is a problem with my combo box. I have
always used the cursor to select the correct data in the combo box and then
selected the next field on the form with the cursor. If I use enter or tab
it goes to the next record on the form. How do I correct that? Again,
thanks for your suggestions! K

Richard said:
khel


He is some code from microsoft's "house hold inventory" template they use
the NotInList function in the double click event.


Private Sub CategoryID_DblClick(Cancel As Integer)
On Error GoTo Err_CategoryID_DblClick
Dim lngCategoryID As Long

If IsNull(Me![CategoryID]) Then
Me![CategoryID].Text = ""
Else
lngCategoryID = Me![CategoryID]
Me![CategoryID] = Null
End If
DoCmd.OpenForm "Categories", , , , , acDialog, "GotoNew"
Me![CategoryID].Requery
If lngCategoryID <> 0 Then Me![CategoryID] = lngCategoryID

Exit_CategoryID_DblClick:
Exit Sub

Err_CategoryID_DblClick:
MsgBox Err.Description
Resume Exit_CategoryID_DblClick
End Sub


notice no use of the acformadd ? take a look at this line.

DoCmd.OpenForm "Categories", , , , , acDialog, "GotoNew"

You may be able to use this in your project.


HTH
Richard



Richard said:
Khel

This is where I found the info on "acformadd"
http://www.blueclaw-db.com/docmd_openform_example.htm
About half way down the page.

Microsoft has a similar explaination in there kb. If it was me I would try
and comment out that line and see what happens.

Richard


:

I thought acFormAdd was to add data to the referenced form to fill the info
in the combo box, not the "base form." I have a "base form," frmMonthly
Purchaser Price Info which includes a combo box, Combo16. This combo box has
a notinlist event that is listed below. The form, frmField Info, is opened
with this event and new data is listed to populate the combo box on
frmMonthly Purchaser. However, once returning to the "base form," frmMonthly
Purchaser I am no longer on the record I was adding, I have advanced one
record with only the information that I added from frmField Info on the
preceding record. I would like to return to the original record that I was
attempting to add on the base form, before I chose the notinlist event option
of adding data to my combo box. I don't know if I have further confused the
situation with my explanation. Thanks for your help. K

:

I have the following written to the NotInList event to add a new name to a
combo box in a form:

Option Compare Database
Option Explicit

Private Sub Combo16_NotInList(NewData As String, Response As Integer)
Dim strMsg As String
strMsg = "Add new field name?"
If MsgBox(strMsg, vbYesNo) = vbYes Then
'open form and pass NewData
DoCmd.OpenForm "frmField Info", , , , acFormAdd, acDialog, NewData
Response = acDataErrAdded 'tell access to requery combo

Else
'cancel even and undo typing
Response = acDataErrContinue
Me.Undo

End If
End Sub

However, after I return from the referenced form "frmField Info" to the
original form I am no longer on the same record. I have advanced to the next
record with only the updated field on the preceding added record. Any
suggestions on how to return to the correct record? Thanks!
 

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