Results 1 to 12 of 12

Thread: Ok here is my problem.

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Sep 2002
    Location
    Devon, UK
    Posts
    311

    Ok here is my problem.

    I have made a database, which i am allowing to add new rows of info, now i have 5 columns.

    So i have made a button, which opens a new form, with some text boxes on. I have 5 text boxes on this new form, and i want to be able to fill them in and then press this one button, to add the poece of info from each box into a certain column in the database. But when i click my add button it will only put my first text box in and that is in the first column.

    I know why it does this but not how to fix it.

    my code for my add button goes:

    Private Sub Command1_Click()
    Unload Form2
    Form1.MSFlexGrid1.Refresh
    Form1.MSFlexGrid1.AddItem (Text2.Text)
    End Sub

    i know it is the (Text2.text) that is the problem, but what do i write as extension to that for the certain column number?

    If you understood that please help, if not just ask and i will try explain again.

    thankyou.
    Sam.

  2. #2

    Thread Starter
    Hyperactive Member
    Join Date
    Sep 2002
    Location
    Devon, UK
    Posts
    311
    Sorry i just thought i would keep this up to date. I have still made no progress, so if this isn't answered soon i will post another topic on sorting my database.

    Thankyou and sorry if this is spam.

    Or dont u do that here.
    Sam.

  3. #3
    Hyperactive Member
    Join Date
    Nov 2001
    Location
    Catalonia
    Posts
    397
    Next example shows you how to put two values in columns 0 and 1

    VB Code:
    1. Form1.MSFlexGrid1.Refresh
    2. Form1.MSFlexGrid1.AddItem (Text1.Text)
    3. Form1.MSFlexGrid1.Col = 1
    4. Form1.MSFlexGrid1.Row = Form1.MSFlexGrid1.Rows - 1
    5. Form1.MSFlexGrid1.Text = Text2.Text

    You should define the column before putting the value on it and use Text property to fill it
    Josep Mª

  4. #4

    Thread Starter
    Hyperactive Member
    Join Date
    Sep 2002
    Location
    Devon, UK
    Posts
    311
    ummm i just copied your code into mine and it didn't work, it still puts up the first text box into the first column, but i stil get nothing in the others.

    What do i do?
    Sam.

  5. #5
    Frenzied Member John McKernan's Avatar
    Join Date
    Jan 2002
    Location
    SE PA
    Posts
    1,295
    To add a new row with the data from the textboxes:
    VB Code:
    1. Dim strRow as String
    2. strRow = Text1.text & vbTab & Text2.Text & vbTab & Text3.Text & vbTab & text4.Text & vbtTab & Text5.text
    3.  
    4. Form1.MSFlexGrid1.AddItem strRow

    To add data from the textboxes to a row which already exists:
    VB Code:
    1. Dim gridRow as Integer
    2.  
    3. gridRow = 'set the row number desired
    4.  
    5. With Form1.MSFlexGrid1
    6.    .TextMatrix(gridRow, 0) = Text1.Text
    7.    .TextMatrix(gridRow, 1) = Text2.Text
    8.    .TextMatrix(gridRow, 2) = Text3.Text
    9.    .TextMatrix(gridRow, 3) = Text4.Text
    10.    .TextMatrix(gridRow, 4) = Text5.Text
    11. End With

    Both of these examples assume that you have no fixed column and that Text1 is going into column 0, adjust as needed.

  6. #6
    Hyperactive Member
    Join Date
    Nov 2001
    Location
    Catalonia
    Posts
    397
    Test the following code.

    It is my above example filling three columns and it works for me
    Attached Files Attached Files
    Josep Mª

  7. #7

    Thread Starter
    Hyperactive Member
    Join Date
    Sep 2002
    Location
    Devon, UK
    Posts
    311
    ok i added the new row code, but still i got no text in columns above 0.

    So here is my exact problem.

    I have a form (form1) it has my database, my database has 5 columns.
    I also have a button on form1 opening form2.
    Form 2 has on it..: 1 invisible text box (this is the box that goes into the first column, its the ID)

    then i have 2 visible text boxes, these two won't go into the columns.

    i also have to combo boxes, but these i will worry about after.

    So i am trying to get the text from my 2 visible text boxes, into the 1 and 2 column. the 0 column is done and finsihed. but how do i move to the next one for more text, from a different box.
    Sam.

  8. #8

    Thread Starter
    Hyperactive Member
    Join Date
    Sep 2002
    Location
    Devon, UK
    Posts
    311
    still no luk here is my program (attatched)
    Attached Files Attached Files
    Sam.

  9. #9
    Hyperactive Member
    Join Date
    Nov 2001
    Location
    Catalonia
    Posts
    397
    I adde the following code to the Command1_Click event in form2 and I get columns o, 1 and 2 filled

    VB Code:
    1. Form1.MSFlexGrid1.Refresh
    2. Form1.MSFlexGrid1.AddItem (Text2.Text)
    3. Form1.MSFlexGrid1.Col = 1
    4. Form1.MSFlexGrid1.Row = Form1.MSFlexGrid1.Rows - 1
    5. Form1.MSFlexGrid1.Text = Text3.Text
    6. Form1.MSFlexGrid1.Col = 2
    7. Form1.MSFlexGrid1.Text = Text4.Text
    Josep Mª

  10. #10

    Thread Starter
    Hyperactive Member
    Join Date
    Sep 2002
    Location
    Devon, UK
    Posts
    311
    Whoa thanks that works now, but i had to move unload form2.
    from the button.

    Thanks.
    Sam.

  11. #11
    Hyperactive Member
    Join Date
    Nov 2001
    Location
    Catalonia
    Posts
    397
    I tested it keeping Unload form2 and it was working even transfering the combos.

    What I saw in your code is that if you select existing values on the combos the button is not activated, you need to type something to actibvate the button. I solved it transfering the code from the change event to the click event.
    Josep Mª

  12. #12

    Thread Starter
    Hyperactive Member
    Join Date
    Sep 2002
    Location
    Devon, UK
    Posts
    311
    yea that was a problem, but i fixed it now, i just made
    it so that if the 2 text boxes were filled then the add button would enable.

    But if it is clicked whilst no text is in the 2 combos then an error will appear.
    Sam.

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