Add Record Problem

mohammadagul

PrinceAtif
Local time
Today, 19:59
Joined
Mar 14, 2004
Messages
298
I am using the following code to refer my active form and add new record

Pubrlic function AddRecord()

If [Screen].[ActiveForm].NAME = "InvoiceCredit" Then
DoCmd.GoToRecord , , acNewRec
End If
Else
End function

This works fine all the way till the end of my main form, but as soon as I jump to my sub form this code does not work. I tried using the following but stillnothing happens

If [Screen].[ActiveForm].NAME = "InvoiceSubform" Then
Docmd.gotocontrol “InvoiceNo”
DoCmd.GoToRecord , , acNewRec
End If

Also I tried this

If [Screen].[ActiveControl].NAME = "InvoiceSubform" Then
Docmd.gotocontrol “InvoiceNo”
DoCmd.GoToRecord , , acNewRec
End If

From my main form form the code runs just fine but from my subform it does not..

What am I doing wrong here?
 
Are the forms always used for data entry and nothing else?
 
Yes the Form Are Alwasy used for Data Entry.
 
a subForm is actually a control when used on a Main form so you have to use something like

Set ctlCurrentControl = Screen.ActiveControl
strControlName = ctlCurrentControl.Name

Call Val
If CanOpen Then
If strControlName = "YourSubFormName" Then
 
Or

you could set 'Data Entry' to yes in the forms properties, that way when you open the form it will always go to a new record.
 

Users who are viewing this thread

Back
Top Bottom