Solved

Unable to bind to field or DataMember: 'DateField'

Posted on 2002-07-15
11
2,008 Views
Last Modified: 2012-06-27
I am using Microsoft Access 2000, ADO on a Windows XP stand alone laptop.  I received the above error when I attempt to load the form containing the DTPicker that is used in my program.  The DTPicker is related to a table called "DateTable" which has two fields:  DateID and DateField.
It appears that the only way I can get around this problem is to populate the DateTable with at least one record before the form is loaded.  Is there any way around this problem?  Does anyone have any ideas about this problem?


John
0
Comment
Question by:johnny6
  • 7
  • 2
  • 2
11 Comments
 
LVL 2

Expert Comment

by:Griffon
ID: 7156717
I believe that it depends what you are trying to do. I am guessing that you have a database that links several tables the datetable being one of them and this is why it is complaining.. I think it is trying to pull up a relating DateTable value but falling short because there is none to get.

Try checking out the relationships to make sure that any referential integrity is exactly what you want.

Another thing is the DTPicker might just require a value to begin with place in a default(not used a DTPicker in access).

Griffon.
0
 
LVL 2

Author Comment

by:johnny6
ID: 7159811
Yes I have a database with 16 tables that links them together.  The DateTable is one of them.
The only time I receive this error is the very first time the program is run.  All subsequent runs of the program will not produce any errors.
Yes I am also aware that the referential integrity constraint is specified between two relations and is used to maintain the consistency among tuples of the two relations.  The referential integrity constraint states that a tuple in one relation that refers to another relation must refer to an *existing tuple* in that relation.


The following is a subroutine that will check if the date exists or not.  If it already exists then the form will load normally.  If the DateTable is empty it will add a record to the date table before showing the form:


Private Sub LoadNewDoc()
    Dim f As New frmTankGauging
    Dim cnn As New ADODB.Connection
    Dim rsDateTable As New ADODB.Recordset
       
    ' Open the connection
    cnn.Open "Provider=Microsoft.Jet.OLEDB.4.0;" & _
    "Data Source = '.\TankBase\TankBase.mdb'"
       
    ' Open the DateTable recordset
    rsDateTable.Open "SELECT * FROM DateTable", _
      cnn, adOpenKeyset, adLockOptimistic
       
    If (Not (rsDateTable.RecordCount = 0)) Then
    rsDateTable.Close
    f.Show
    Else 'The DateTable is empty.
    rsDateTable.AddNew
    rsDateTable!DateField = DateValue(Now)
    rsDateTable.Update
    rsDateTable.Close
    f.Show
    End If
   
   
   End Sub




John
0
 
LVL 2

Author Comment

by:johnny6
ID: 7159839
I am still receiving the error even though I am attempting to create a record in the date table before the form loads.  Any ideas?



John
0
 
LVL 2

Expert Comment

by:Griffon
ID: 7159859
One thing that might be happening then is that the value that you are assigning to the DateField in here is done too late as the control has already been created ..(or partially created) so the program is bringin up an error before it is setting the value.

I would try setting the date for the first run under a different event from the one currently used to see if the results that you get are any different.

I am also assuming that dateId is an auto field if not then the reason it kicks up might be because you are not setting a corresponding ID for the date you place within it.
0
 
LVL 18

Accepted Solution

by:
mdougan earned 50 total points
ID: 7159953
One of the truely annoying things about the Date Picker control is that it doesn't allow you to have it blank, unless you check this obnoxious checkmark that says to allow blanks.  I'm guessing that you have to check this mark, either at design time, or programatically before showing your form.
0
U.S. Department of Agriculture and Acronis Access

With the new era of mobile computing, smartphones and tablets, wireless communications and cloud services, the USDA sought to take advantage of a mobilized workforce and the blurring lines between personal and corporate computing resources.

 
LVL 2

Author Comment

by:johnny6
ID: 7160461
mdougan:
         When I tried your suggestion and set the checkbox at design time to True and I received a VB error:  Run Time error 94: Invalid use of Null.
This problem happens because as soon as the DTPicker control loses it's focus and moves to the next control the DTPicker checkbox becomes unchecked and thus losing the date and generating the Run time error 94.



Griffon:
         The control could not possibly be created before I load the form.  However, even if I try to write the  DateField record of the Date Table I will still receive the following error from Visual Basic: "Question: Unable to bind to field or DataMember: 'DateField'".


Does anyone else have any experience using the DTPicker and have run across this same problem?

John
0
 
LVL 18

Expert Comment

by:mdougan
ID: 7160512
Sorry, I had the checkbox backwards, if you uncheck it, it should allow nulls.  If you found it was already unchecked, and were getting that error, then this may not be a solution for you.

Basically, there are two interdependent properties.  If the checkbox is available and checked, then the control has to have a Value.  If you don't have a value (like at startup before you have a valid record) then the checkmark should be blank, and then (order is important here) you can set the value to "".

If you are going to check the checkmark, then you have to first set the value to a valid date.

It might be that all you need to do is set the value at design time to a valid date.  Assuming that all of your records have a valid date in the column you are attaching the date picker to.
0
 
LVL 2

Author Comment

by:johnny6
ID: 7160519
Griffon wrote, "I am also assuming that dateId is an auto field if not then the reason it kicks up might be because you are not setting a corresponding ID for the date you place within it."

Yes the DateID in the DateTable is an autofield.

If I try setting the date in the corresponding field of the other table then I receive an error from VB something like "Record cannot be updated because you must include the data for the Inspector record.  Unfortunately, the only way to enter data into the Inspector field is to first load the form.  However, we can't lod the form until we first set the dates for both DateID's in the DateTable and the TankGauging table.

It seems that we have a catch-22 problem here...


Does anyone have any ideas how to get around the above problems?

I noticed that this control seems to be similar in it's functionality to the DataCombo control in that it appears that both joined tables of both controls must be populated with data before they work correctly.

Does anyone know for sure if this is the case for the DTPicker?


John
0
 
LVL 2

Author Comment

by:johnny6
ID: 7160538
Griffon wrote, "I am also assuming that dateId is an auto field if not then the reason it kicks up might be because you are not setting a corresponding ID for the date you place within it."

Yes the DateID in the DateTable is an autofield.

If I try setting the date in the corresponding field of the other table then I receive an error from VB something like "Record cannot be updated because you must include the data for the Inspector record.  Unfortunately, the only way to enter data into the Inspector field is to first load the form.  However, we can't lod the form until we first set the dates for both DateID's in the DateTable and the TankGauging table.

It seems that we have a catch-22 problem here...


Does anyone have any ideas how to get around the above problems?

I noticed that this control seems to be similar in it's functionality to the DataCombo control in that it appears that both joined tables of both controls must be populated with data before they work correctly.

Does anyone know for sure if this is the case for the DTPicker?


John
0
 
LVL 2

Author Comment

by:johnny6
ID: 7165087
mdougan:
        Post a comment on my other question: http://www.experts-exchange.com/jsp/qManageQuestion.jsp?ta=visualbasic&qid=20324454  and I will awarrd you the points for it.


        It seems that the only way I was able to solve this problem is to do the following:

1) At design time set the checkbox property to true and set the value property to blank.

2) In the form load subroutine set the
0
 
LVL 2

Author Comment

by:johnny6
ID: 7165133
2) In the form that contains the DTPicker control's form load subroutine I assigned the DTPicker1.CheckBox = False and DTPicker1.Value = Date.

3) Before the form loads, I used my previously mentioned code to check if the Date Table was empty or not.

mdougan is correct about the DTPicker control being very finicky when both tables that rely on that control are empty.


John
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

It took me quite some time to sort out all the different properties of combo and list boxes available from Visual Basic at run-time. Not that the documentation is lacking: the help pages are quite thorough and well written. The problem was rather wh…
Regardless of which version on MS Access you are using, one of the harder data-entry forms to create is one where most data from previous entries needs to be appended to new records, especially when there are numerous fields and records involved.  W…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

920 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

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now