On current always add a new record?

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Please help with this code:
Private Sub Form_Current()
Static StrWorkerID As String
Static LgCaseNum As Integer
If Me.NewRecord Then
Me.WorkerID = [Forms]![FrmEditCase]![SubformCase].[Form]![WorkerID]
Me.Text78 = [Forms]![FrmCaseSearch].[CaseNoBox]
End If
End Sub
Thank you in advange.
MN
 
What is it you need help with? Do you want this code explained?
Static StrWorkerID As String
Static LgCaseNum As Integer
These create 2 variables that will remember their value each time you enter
the routine, as long as the form remains open. This is done by using the
Static keyword instead of Dim.
If Me.NewRecord Then
Me.WorkerID = [Forms]![FrmEditCase]![SubformCase].[Form]![WorkerID]
Me.Text78 = [Forms]![FrmCaseSearch].[CaseNoBox]
End If

The Current event runs each time the form goes to a different record,
including moving to the first record as the form opens and when moving to a
new record when you want to add another record. The If statement here checks
to see if you are at a new record and if you are, then assign the values
from the forms FrmEditCase (actually from a control on a subform of
FrmEditCase) and FrmCaseSearch to the controls on this form. These other two
forms must be open at the time the code runs in order for this to work.

--
Wayne Morgan
MS Access MVP


MN said:
Please help with this code:
Private Sub Form_Current()
Static StrWorkerID As String
Static LgCaseNum As Integer
If Me.NewRecord Then
Me.WorkerID = [Forms]![FrmEditCase]![SubformCase].[Form]![WorkerID]
Me.Text78 = [Forms]![FrmCaseSearch].[CaseNoBox]
End If
End Sub
 
Thank for reply.
Here my situation. I have a Mainform with a 5 page. Each page I have a
subform, from SubForm1 to SubForm5 each SubForm have a table.
In the subform, I have On Current Event in order to let the user click
Navigation to Add a new record. But it is always add a new record at the end
of each table (5 table) when the form is loaded - even I am not click to add
a new record yet !!!
So, I wonder when the form is load it always add a new record? (my Onload
Event is nothing right now)
If I remove On current event then it is working fine but the user can not
add a new record by clicking on Navigation button. Any idea thanks a lot in
advange.
Regards,
MN

Wayne Morgan said:
What is it you need help with? Do you want this code explained?
Static StrWorkerID As String
Static LgCaseNum As Integer
These create 2 variables that will remember their value each time you enter
the routine, as long as the form remains open. This is done by using the
Static keyword instead of Dim.
If Me.NewRecord Then
Me.WorkerID = [Forms]![FrmEditCase]![SubformCase].[Form]![WorkerID]
Me.Text78 = [Forms]![FrmCaseSearch].[CaseNoBox]
End If

The Current event runs each time the form goes to a different record,
including moving to the first record as the form opens and when moving to a
new record when you want to add another record. The If statement here checks
to see if you are at a new record and if you are, then assign the values
from the forms FrmEditCase (actually from a control on a subform of
FrmEditCase) and FrmCaseSearch to the controls on this form. These other two
forms must be open at the time the code runs in order for this to work.

--
Wayne Morgan
MS Access MVP


MN said:
Please help with this code:
Private Sub Form_Current()
Static StrWorkerID As String
Static LgCaseNum As Integer
If Me.NewRecord Then
Me.WorkerID = [Forms]![FrmEditCase]![SubformCase].[Form]![WorkerID]
Me.Text78 = [Forms]![FrmCaseSearch].[CaseNoBox]
End If
End Sub
 
There is nothing in the Current event that you posted that would cause a
form to move to a new record. The code you posted will react to moving to a
new record, but you'll have to move there first before that code would do
anything.
 
Thanks Wayne for taking your time.
But If I remove this code then no record add in !?
Then if I add these code in then the table alwa add a new record !?
Any ideal? I am using MS2K Developer version, Win2K ;-?
Regards, MN
 
But If I remove this code then no record add in !?

By this do you mean that without this code that you can NOT add a new
record? That may well be the case. It appears that the code generates an ID
field value that probably needs to link to records in associated tables and
Access won't accept a new record without a value for this field.

However, not being able to save a new record is NOT the same as not being
able to go to the new record position on a form. It just means that once
you're there, you can't save it.

What EXACTLY are you having a problem with?
 
Back
Top