Results 1 to 10 of 10

Thread: Data1.Recordset.AddNew

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Sep 2007
    Posts
    19

    Data1.Recordset.AddNew

    hello all,.

    i am working on a program that does add, delete, update and find, so far i managed with all except for add,

    i have the below code:
    Dim strBufferTaper As String

    strBufferTaper = txttaper.Text
    DataTaperCode.UpdateControls
    DataTaperCode.Recordset.AddNew
    txttaper.Text = strBufferTaper
    DataTaperCode.Recordset.MoveNext
    DataTaperCode.Recordset.AddNew

    which works fine to add a new record to a table called Taper

    how do i enhance this code to check for duplicate in the table before adding the new record, if the record already exist, give a message box, if not, then add the new record from the user input (txttaper.text)

    please help

    thank you in advance

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

    Re: Data1.Recordset.AddNew

    It would be easy enough using programming code, but I don't know of a way using a bound data control.

  3. #3

    Thread Starter
    Junior Member
    Join Date
    Sep 2007
    Posts
    19

    Re: Data1.Recordset.AddNew

    how do i use programming code, as you suggested, could you teach me?

  4. #4
    PowerPoster
    Join Date
    Feb 2006
    Location
    East of NYC, USA
    Posts
    5,691

    Re: Data1.Recordset.AddNew

    The most difficult part of developing a program is understanding the problem.
    The second most difficult part is deciding how you're going to solve the problem.
    Actually writing the program (translating your solution into some computer language) is the easiest part.

    Please indent your code and use [HIGHLIGHT="VB"] [/HIGHLIGHT] tags around it to make it easier to read.

    Please Help Us To Save Ana

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

    Re: Data1.Recordset.AddNew

    Once you are comfortable in connecting via code, we can take a look as using the SQL SELECT query to return a value from your database.

  6. #6

    Thread Starter
    Junior Member
    Join Date
    Sep 2007
    Posts
    19

    Re: Data1.Recordset.AddNew

    hi

    i went through the tutorial.... could you show me on the sql part?

    thanks

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

    Re: Data1.Recordset.AddNew


  8. #8

    Thread Starter
    Junior Member
    Join Date
    Sep 2007
    Posts
    19

    Re: Data1.Recordset.AddNew

    hello

    thanks for the sql tutorial, i managed on the below codes:

    Set DB = OpenDatabase(App.Path & "\Project Light Speed.mdb")
    SQL = "select * from [Taper_Code] where Taper_Code ='" & txttaper.Text & "'"
    Set rs = DB.OpenRecordset(SQL)

    SQL = "insert into Taper_Code (Taper_Code) " & _
    "values ('" & txttaper.Text & "')"
    DB.Execute SQL

    How do i implement that after i select the record, if not found then do the insert part, else display a message box?

    please help

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

    Re: Data1.Recordset.AddNew

    Code:
    Set DB = OpenDatabase(App.Path & "\Project Light Speed.mdb")
    SQL = "select * from [Taper_Code] where Taper_Code ='" & txttaper.Text & "'"
    Set rs = DB.OpenRecordset(SQL)
    If rs.RecordCount = 0 Then 'it does not exist
       SQL = "insert into Taper_Code (Taper_Code) " & _
        "values ('" & txttaper.Text & "')"
        DB.Execute SQL
    Else
        MsgBox txttaper.text & " already exists in the database."
    End If

  10. #10

    Thread Starter
    Junior Member
    Join Date
    Sep 2007
    Posts
    19

    Re: Data1.Recordset.AddNew

    hack,

    Thank you so much for your help, that code works great.

    joyce

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