Page 1 of 2 12 LastLast
Results 1 to 15 of 22
  1. #1
    sukhjinder's Avatar
    sukhjinder is offline Beginner
    Windows 10 Access 2016
    Join Date
    May 2016
    Posts
    43

    Getting error while entering the first record in recordset


    I am a new to ms access. Please help me i am not able to enter my first record into the database.
    Attached Files Attached Files

  2. #2
    andy49's Avatar
    andy49 is offline VIP
    Windows 10 Access 2007
    Join Date
    Nov 2016
    Location
    London
    Posts
    1,051
    We're gonna need more info here. What do you want to happen.


    Sent from my iPhone using Tapatalk

  3. #3
    andy49's Avatar
    andy49 is offline VIP
    Windows 10 Access 2007
    Join Date
    Nov 2016
    Location
    London
    Posts
    1,051
    Have you considered binding your form to the tblbattery. That way the changes that you make would automatically update.

    This may be useful
    http://stackoverflow.com/questions/1...s-in-ms-access




    Sent from my iPhone using Tapatalk

  4. #4
    sukhjinder's Avatar
    sukhjinder is offline Beginner
    Windows 10 Access 2016
    Join Date
    May 2016
    Posts
    43
    [QUOTE=andy49;341533]We're gonna need more info here. What do you want to happen.


    sir please look into the attachment
    Attached Thumbnails Attached Thumbnails Capture.PNG  

  5. #5
    sukhjinder's Avatar
    sukhjinder is offline Beginner
    Windows 10 Access 2016
    Join Date
    May 2016
    Posts
    43
    sir i donot want to bind the text boxes i want to enter the data through VBA programming. I know my program will work if it had some data in tblbattery.but how to initially enter the data into the table thorough vba

  6. #6
    Bob Fitz's Avatar
    Bob Fitz is offline Access Developer
    Windows 7 32bit Access 2013
    Join Date
    May 2011
    Location
    Essex UK
    Posts
    3,544
    Perhaps something like:
    Code:
    Private Sub Form_Load()
      Dim db As DAO.Database
      Dim rs As DAO.Recordset
        Set db = CurrentDb
        Set rs = db.OpenRecordset("tbl_battery", dbOpenDynaset, dbSeeChanges)
        
        If Not rs.BOF Then
        
            Me.txtid = rs!id
            Me.txtsname = rs!sname
            Me.txtoem = rs!oem
            Me.txtcontno = rs!contno
            Me.txtallotslno = rs!allotedslno
            Else
            Exit Sub
        End If
    End Sub
    If this helped, please click the star at the bottom left of this posting and add to my reputation . Many thanks.
    Bob Fitzpatrick

  7. #7
    Micron is offline Virtually Inert Person
    Windows 7 32bit Access 2007
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,801
    This isn't a comment on the previous post, just an explanation of the error for the benefit of the OP.
    MoveFirst is an action. It has no Null or other such properties. You would have to MoveFirst, then check if a specific field in that record is Null or not.
    Your attempts to move first/previous/next will generate errors if there are no records/you are at the first/you are at the last record of a recordset because you haven't trapped for those errors.
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  8. #8
    sukhjinder's Avatar
    sukhjinder is offline Beginner
    Windows 10 Access 2016
    Join Date
    May 2016
    Posts
    43

    Smile

    Quote Originally Posted by Bob Fitz View Post
    Perhaps something like:
    Code:
    Private Sub Form_Load()
      Dim db As DAO.Database
      Dim rs As DAO.Recordset
        Set db = CurrentDb
        Set rs = db.OpenRecordset("tbl_battery", dbOpenDynaset, dbSeeChanges)
        
        If Not rs.BOF Then
        
            Me.txtid = rs!id
            Me.txtsname = rs!sname
            Me.txtoem = rs!oem
            Me.txtcontno = rs!contno
            Me.txtallotslno = rs!allotedslno
            Else
            Exit Sub
        End If
    End Sub

    Thanks
    sir your code really help me but i have improved a little bit more in editing and getting data i want to share it with you

    Option Compare Database
    Option Explicit


    Dim db As Database
    Dim rs As Recordset


    Private Sub cmdclose_Click()
    DoCmd.Close
    End Sub


    Private Sub cmddelete_Click()
    Dim msg As String
    msg = "Are you sure that you want to delete this record?"

    If MsgBox(msg, vbYesNo, "Are you sure?") = vbOK Then
    rs.Delete
    End If

    End Sub


    Private Sub cmdmovenext_Click()
    If Not rs.EOF Then
    rs.MoveNext
    refreshdata
    End If

    If rs.EOF Then
    rs.MovePrevious
    End If
    End Sub


    Private Sub cmdmoveprevious_Click()
    If Not rs.BOF Then
    rs.MovePrevious
    refreshdata
    End If

    If rs.BOF Then
    rs.MoveNext
    End If

    End Sub


    Private Sub cmdnew_Click()
    Me.txtid = ""
    Me.txtsname = ""
    Me.txtoem = ""
    Me.txtcontno = ""
    Me.txtallotslno = ""
    Me.txtsname.SetFocus
    End Sub


    Private Sub cmdsave_Click()
    If Me.txtid = "" Then
    rs.AddNew
    Else
    rs.Edit
    End If
    rs!SNAME = Me.txtsname
    rs!oem = Me.txtoem
    rs!containerno = Me.txtcontno
    rs!allotedslno = Me.txtallotslno
    rs.Update
    End Sub


    Private Sub Form_Load()
    Set db = CurrentDb
    Set rs = db.OpenRecordset("tbl_battery", dbOpenDynaset, dbSeeChanges)
    refreshdata
    End Sub


    Private Sub refreshdata()
    If Not rs.BOF And Not rs.EOF Then
    Me.txtid = rs!id
    Me.txtsname = rs!SNAME
    Me.txtoem = rs!oem
    Me.txtcontno = rs!containerno
    Me.txtallotslno = rs!allotedslno
    End If
    End Sub


    but i want some more help of you sir every battery consist of 5 cells each
    how to enter five records differently in the record set

  9. #9
    Bob Fitz's Avatar
    Bob Fitz is offline Access Developer
    Windows 7 32bit Access 2013
    Join Date
    May 2011
    Location
    Essex UK
    Posts
    3,544
    every battery consist of 5 cells each
    how to enter five records differently in the record set
    Sound as though you need a table for the batteries and another related table for the details of the 5 cells.
    If this helped, please click the star at the bottom left of this posting and add to my reputation . Many thanks.
    Bob Fitzpatrick

  10. #10
    Micron is offline Virtually Inert Person
    Windows 7 32bit Access 2007
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,801
    agreed. If you already have that, then I think as long as you're using recordsets, you'll have to create another one that gives you the values you need, and when writing one set of values, you have to loop through the second and get those values and do whatever with them. That loop has to be nested within the code that gives you access to the first recordset. Quite often, simple queries based on a set of form controls are much easier to deal with and do the job. Not sure, but I see no reason here why the complicated route of using recordsets has been chosen.

  11. #11
    ssanfu is offline Master of Nothing
    Windows XP Access 2010 32bit
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    You should also make these changes:
    Code:
    Option Compare Database
    Option Explicit
    
    Dim db As DAO.Database
    Dim rs As DAO.Recordset
    
    Private Sub cmdclose_Click()
        On Error Resume Next
        rs.Close
        Set rs = Nothing
        Set db = Nothing
       DoCmd.Close acForm, Me.Name
    
    End Sub

  12. #12
    sukhjinder's Avatar
    sukhjinder is offline Beginner
    Windows 10 Access 2016
    Join Date
    May 2016
    Posts
    43
    Quote Originally Posted by ssanfu View Post
    You should also make these changes:
    Code:
    Option Compare Database
    Option Explicit
    
    Dim db As DAO.Database
    Dim rs As DAO.Recordset
    
    Private Sub cmdclose_Click()
        On Error Resume Next
        rs.Close
        Set rs = Nothing
        Set db = Nothing
       DoCmd.Close acForm, Me.Name
    
    End Sub
    yours code really helped a lot in the closing part of the database. thanks

    Next step i am working on the table of cells as suggested by

    Quote Originally Posted by Bob Fitz View Post
    Sound as though you need a table for the batteries and another related table for the details of the 5 cells.

  13. #13
    ssanfu is offline Master of Nothing
    Windows XP Access 2010 32bit
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    You really should step back and design your table structures using pencil & paper, cardboard, whiteboard, etc.
    It doesn't seem like you know where you are headed with the dB. test the design manually. Once it seems to work, then and only then should you open Access and start creating objects.

    Why don't you want to use bound forms? Easier and less programming....

    You know this will probably require another table??

    Please describe what you are trying to do without using Access jargon.

  14. #14
    sukhjinder's Avatar
    sukhjinder is offline Beginner
    Windows 10 Access 2016
    Join Date
    May 2016
    Posts
    43
    My road map in creating the database is clear and i am determined that i will complete this. I have checked and come with a workable design that i will finish this with VBA. The database is further
    You know this will probably require another table??
    beyond requirement another table. it will do analysis and give the report individually. Where i was stuck up is little help in minimizing coding errors. i am trying and adding beauty to the database. thanks

  15. #15
    sukhjinder's Avatar
    sukhjinder is offline Beginner
    Windows 10 Access 2016
    Join Date
    May 2016
    Posts
    43
    Quote Originally Posted by Bob Fitz View Post
    Sound as though you need a table for the batteries and another related table for the details of the 5 cells.
    how to enter all the five records at a time through VBAClick image for larger version. 

Name:	Capture1.PNG 
Views:	17 
Size:	9.2 KB 
ID:	26846battery.zip

Page 1 of 2 12 LastLast
Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 1
    Last Post: 06-30-2016, 04:57 PM
  2. I need help with an error made entering data.
    By raycatena in forum Access
    Replies: 7
    Last Post: 06-29-2015, 05:14 PM
  3. Error entering new record on a subform
    By AccessNewb11 in forum Access
    Replies: 1
    Last Post: 07-24-2014, 11:49 AM
  4. Error on entering duplicate value
    By anwaar in forum Programming
    Replies: 3
    Last Post: 09-02-2011, 01:25 PM
  5. Replies: 1
    Last Post: 06-15-2011, 03:29 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums