I have programmed user forms in Word and Project without problems but I am having problems loading Form1 in MS Access. It gives me this error:
Object variable or With block not set
The form does launch when I use DoCmd.OpenForm "Form1", acNormal, , , , acDialog
.
I now understand that Load Form1
does not work in MS Access. So I must use DoCmd.OpenForm...
But I am still having problems accessing the data entered on the form.
My form has two entry fields: frm_Company and frm_Date
, Below is the code.
Dim str_Company as String 'variable to capture result for form input
Dim date_Forecast as String 'variable to capture result of form input
DoCmd.OpenForm "Form1", acNormal, , , , acDialog
str_Company = Forms!Form1!frm_Company
date_Forecast = Forms!Form1!frm_Date
When the code is executed Form1 launches, the user enters the data for the two field and presses a "Close Form" button. When VBA tries to execute the last two lines I get the error:
Microsoft cannot find the referenced form Form1
Thanks for your assistance.
Form1 As Form
, and then use it without assigning that variable any reference, you are referring to an invalid object reference and that will always raise error 91. Access forms are document modules, like Worksheet modules in Excel: they're owned by Access, not VBA: they have very little in common with userforms, other than "form" as part of the name. – Mathieu GuindonMe
refers to the current object, you can't use it outside the form to refer to that form. – Mathieu GuindonForm1
that will loaded into every record of the database along with data obtained from the Excel spreadsheet. – Kaiser Otto