Barbara
Barbara

Reputation: 14806

AutofillNewRecord type mismatch in subform

I need to fill a new record with data from the previous record. I don't know vba but I found this article: https://support.microsoft.com/en-us/kb/210236

Since I want all the fields to be automatically written in, I've just c/p the code and put =AutofillNewRecord([Forms]![Abc]) on the current event property of Abc. It works perfectly.

Now the problem is Abc is actually a subform for MainForm. So, if I open Abc directly it's all fine but when I open it through MainForm it says "type mismatch" and the function (?) doesn't work at all.

The expression OnCurrent you entered as the event property setting produced the following error: Type mismatch.

The expression may not result in the name of a macro, the name of a user-defined function, or [Event Procedure].

There may have been an error evaluating the function, event, or macro.

I've searched on Google but I couldn't find a solution. I'm attaching a bare-bones example hoping someone could help. https://www.dropbox.com/s/6fpnhkpreb75rxw/AutofillTest.accdb?dl=0

Btw, since I'm using a non-english version of Access you might need to change =AutofillNewRecord([Maschere]![abc]) under on current event to =AutofillNewRecord([Forms]![abc]).

Upvotes: 0

Views: 96

Answers (1)

Alexander Remesch
Alexander Remesch

Reputation: 623

One solution would be to use an event procedure instead of directly entering =AutofillNewRecord([Forms]![Abc]) for the Form_Current() event:

Private Sub Form_Current()
    AutoFillNewRecord Me
End Sub

I've tried with your database and it worked here, independently of whether the form is used as subform (also independent of which parent) or opened as main form.

Upvotes: 1

Related Questions