Results 1 to 3 of 3

Thread: ADDING TO A DATABASE - DIFFICULT

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Jan 2000
    Location
    WALES UK
    Posts
    31
    Dim lFrom as long, lTo as Long, l as Long
    ' check if values are entered
    ' code goes here

    ' read out entered values
    lFrom = Clng(Val(Text1.Text))
    lTo = Clng(Val(Text2.Text))
    ' validate if From < To
    ' code goes here

    ' loop from lFrom to lTo
    For l = lFrom to lTo
    ' do something with l
    ' so that I can add all the
    ' numbers to the database
    Next

    My database is called carpet database and the table I wish to store the details in is called invoice numbers and the field is called invoice number...
    If the user types in 100 and 300 as the two values I need to add these and all the numbers in between to my database for validation in other forms...

    Can anybody help cos this is really streesing me out!!!

    Cheers

    Rhys


  2. #2
    Frenzied Member Mark Sreeves's Avatar
    Join Date
    Nov 1999
    Location
    UK
    Posts
    1,845
    Don't get stressed...

    firstly, don't use spaces in table or field names

    You'll need a reference to DAO stuff

    is this what you require?
    Code:
    Private Sub Command1_Click()
    Dim l As Integer
    Dim db As DAO.Database
    Dim strSQL As String
    
    Set db = DAO.OpenDatabase("C:\carpet Database.mdb")
    
    
    ' loop from lFrom to lTo
    For l = lFrom To lTo
    ' do something with l
    ' so that I can add all the
    ' numbers to the database
      strSQL = "INSERT INTO invoiceNumbers (invoiceNumber) VALUES(" & l & ");"
    
    db.Execute strSQL
    
    
    Next
    db.Close
    Set db = Nothing
    
    
    End Sub
    Mark
    -------------------

  3. #3
    New Member
    Join Date
    Mar 2000
    Posts
    14
    if you must use spaces in table or field name then when reference it surround it with spare brackets ie [my table].field1

    FireBeast

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