Link to home
Start Free TrialLog in
Avatar of John Sobiranski
John SobiranskiFlag for United States of America

asked on

Unable to bind to field or DataMember: 'DateField'

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
Avatar of Griffon
Griffon

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.
Avatar of John Sobiranski

ASKER

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
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
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.
ASKER CERTIFIED SOLUTION
Avatar of mdougan
mdougan
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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
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.
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
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
mdougan:
        Post a comment on my other question: https://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
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