Solved

Error - you tried to assign a null value to a variable that is not a variant data type

Posted on 2014-10-24
9
502 Views
Last Modified: 2014-10-24
When I want to enter data into the main form I get the error: you tried to assign a null value to a variable that is not a variant data type, when I click out of it everything works fine.

What is causing that error?
How can I fix it?

Thanks!
Contacts.accdb
0
Comment
Question by:Coaster_brook_trout
  • 5
  • 2
  • 2
9 Comments
 
LVL 19

Expert Comment

by:Eric Sherman
ID: 40402434
I have your main form open ... Please post the steps to reproduce your error.

Thanks,

ET
0
 
LVL 19

Expert Comment

by:Eric Sherman
ID: 40402477
Your sub form is linked to the main form using the Contact ID field.  When you create a new record you must populate the Contact ID field first.

ET
0
 

Author Comment

by:Coaster_brook_trout
ID: 40402586
Thanks etsherman, my Contact ID field is an autonumber. How do I get it and set it before a new record is created?
0
Use Case: Protecting a Hybrid Cloud Infrastructure

Microsoft Azure is rapidly becoming the norm in dynamic IT environments. This document describes the challenges that organizations face when protecting data in a hybrid cloud IT environment and presents a use case to demonstrate how Acronis Backup protects all data.

 
LVL 19

Accepted Solution

by:
Eric Sherman earned 300 total points
ID: 40402693
<<<<<hanks etsherman, my Contact ID field is an autonumber. How do I get it and set it before a new record is created?>>>>>

Ok, looks like you have your main form and sub forms not properly structured.  Your main form should be the Contact information form that establishes the record.  Then link that main from to the sub forms such as Children, Interest, etc.

See picture below.

Sample1
0
 
LVL 61

Assisted Solution

by:mbizup
mbizup earned 200 total points
ID: 40402726
It doesn't even need to be that complex...

From what I can tell the main purpose of the main form is to located a contact record and to display it in the subform.

That structure is fine, but there is no need for the link between the master and child forms, or for the main form to be bound to a table.

You can make the main form unbound, remove the master/child links and use the combo boxes to search for the subform record, simplifying the after update code like this (you'll have to use your own form/field/control names, etc):

Dim rs as Dao.recordset
Set rs = Me.MySubformName.Form.Recordset Clone
rs.FindFirst "Field1 LIKE '" & NZ(me.combo1, "*")  & "' AND Field2 LIKE '" & NZ(me.combo2, "*") &"'"
if rs.NoMatch = False Then
    Me.MySubformName.Form.Bookmark = rs.BookMark  '<---- moves the subform to the selected record
Else
   msgbox "Record Not Found"
End If

Open in new window


And also move your navigation controls to the subform, so that they control the records in the subform directly rather than indirectly through the master child links (which is the source of your error message).
0
 
LVL 19

Expert Comment

by:Eric Sherman
ID: 40402849
My solution was geared at answering the question that was asked as opposed to redeveloping what was already done.  If he makes the main form the Contact form to establish the Contact ID record given what he already has ... that seems a lot LESS complex compared to the last post!!!

ET
0
 

Author Closing Comment

by:Coaster_brook_trout
ID: 40402914
Both of you are incredibly thorough and easy to understand, thank you, excellent responses!
0
 
LVL 61

Expert Comment

by:mbizup
ID: 40402922
Glad to help out!

>>  If he makes the main...

ET,  I think 'she' in this case :-)
0
 
LVL 19

Expert Comment

by:Eric Sherman
ID: 40403143
OOPs ... Sorry Coaster brook trout for referring to you as he instead she.  Thanks for the points.

Thanks mbizup for reminding me!!!

ET
0

Featured Post

The Eight Noble Truths of Backup and Recovery

How can IT departments tackle the challenges of a Big Data world? This white paper provides a roadmap to success and helps companies ensure that all their data is safe and secure, no matter if it resides on-premise with physical or virtual machines or in the cloud.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
update query 4 28
How to replace a blank field with a zero in a query in Access 2010 10 38
Access 2010 change CurrentUser 5 37
SQL Select in Access 2003 3 27
QuickBooks® has a great invoice interface that we were happy with for a while but that changed in 2001 through no fault of Intuit®. Our industry's unit names are dictated by RUS: the Rural Utilities Services division of USDA. Contracts contain un…
Preparing an email is something we should all take special care with – especially when the email is for somebody you may not know very well. The pressures of everyday working life stacked with a hectic office environment can make this a real challen…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

820 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question