Results 1 to 6 of 6

Thread: Displaying Datafield Command1.lname not found.

  1. #1

    Thread Starter
    New Member
    Join Date
    Jul 2013
    Posts
    3

    Displaying Datafield Command1.lname not found.

    This is the code which I have written to display data report based on roomno.
    But I am getting error as 'Datafield Command1.lname' not found.
    Need help to resolved this.
    Code:
    Private Sub Command1_Click()
    Dim conn28 As New ADODB.Connection
    Dim str28 As String
    Dim Constr28 As String
        Set conn28 = New ADODB.Connection
        Constr28 = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & App.Path & "\ShowData.mdb;Persist Security Info=False" 'This is a string which are used to set path and security of access database
        conn28.Open Constr28
    
        Dim rs28 As New ADODB.Recordset
        rs28.Open "Select name,addr,city,pincode,mobno,chkindate,roomno,roomtype,rentperday,advpaid rom CheckIn where roomno=('" & Text8.Text & "')", conn28, adOpenStatic, adLockReadOnly
    
        With DataReport1
            .DataMember = vbNullString
          Set .DataSource = rs28
          With .Sections("Section1").Controls
            .Item("txtlname").DataField = Text1.Text 'lname
            .Item("txtaddr").DataField = Text15.Text 'addr
            .Item("txtcity").DataField = Text5.Text 'city
            .Item("txtpincode").DataField = Text6.Text 'pincode
            .Item("txtmobno").DataField = Text4.Text  'mobno
            .Item("txtchkindate").DataField = DTPicker1.Value 'chkindate
            .Item("txtroomno").DataField = Text8.Text  'roomno
            .Item("txtroomtype").DataField = List3.Text 'roomtype
            .Item("txtrentperday").DataField = Text9.Text 'rentperday
            .Item("txtadvpaid").DataField = txtadvpaid.Text 'advpaid
          End With
        .Show vbModal
        End With
    
        rs28.Close
        conn28.Close
    End SUb
    Last edited by Hack; Jul 29th, 2013 at 06:04 AM. Reason: Added Code Tags

  2. #2
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: Displaying Datafield Command1.lname not found.

    Welcome to the forums

    What line of code is causing the error?

  3. #3

    Thread Starter
    New Member
    Join Date
    Jul 2013
    Posts
    3

    Re: Displaying Datafield Command1.lname not found.

    .Item("txtlname").DataField = Text1.Text 'lname


    in the above line, I am getting error as 'Datafield.command1.lname' is not found.

  4. #4
    PowerPoster
    Join Date
    Sep 2005
    Location
    Modesto, Ca.
    Posts
    5,195

    Re: Displaying Datafield Command1.lname not found.

    Did you set the reports datasource property or datamember property during the design? It looks like maybe you used a dataenviroment. If so, remove those property settings.

  5. #5

    Thread Starter
    New Member
    Join Date
    Jul 2013
    Posts
    3

    Re: Displaying Datafield Command1.lname not found.

    Checked it with removing the properties. But still it is displaying the same error 'Datafield Command1.lname' not found.

  6. #6
    PowerPoster
    Join Date
    Sep 2005
    Location
    Modesto, Ca.
    Posts
    5,195

    Re: Displaying Datafield Command1.lname not found.

    Yeah, you also need to remove the datamember property for each textbox on the report. Also, this doesn't seem right,

    Code:
       Dim rs28 As New ADODB.Recordset
        rs28.Open "Select name,addr,city,pincode,mobno,chkindate,roomno,roomtype,rentperday,advpaid rom CheckIn where roomno=('" & Text8.Text & "')", conn28, adOpenStatic, adLockReadOnly
    
        With DataReport1
            .DataMember = vbNullString
          Set .DataSource = rs28
          With .Sections("Section1").Controls
            .Item("txtlname").DataField = Text1.Text 'lname
            .Item("txtaddr").DataField = Text15.Text 'addr
            .Item("txtcity").DataField = Text5.Text 'city
            .Item("txtpincode").DataField = Text6.Text 'pincode
            .Item("txtmobno").DataField = Text4.Text  'mobno
            .Item("txtchkindate").DataField = DTPicker1.Value 'chkindate
            .Item("txtroomno").DataField = Text8.Text  'roomno
            .Item("txtroomtype").DataField = List3.Text 'roomtype
            .Item("txtrentperday").DataField = Text9.Text 'rentperday
            .Item("txtadvpaid").DataField = txtadvpaid.Text 'advpaid
          End With
        .Show vbModal
        End With
    If you want to use rs28 as your datasource then why are you setting the datafields values to the forms textbox values? Just set the datafield property in the report designer for each report textbox on the report to the corresponding field name in the recordset, like name, address, city ...

    btw - I don't see any field in the recordset called "lname", only one called "name"

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width