Results 1 to 16 of 16

Thread: flexgrid update problem

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Aug 2005
    Posts
    261

    flexgrid update problem

    I am developing an application in VB6, MS Access 2003, where i get an error when updating the data. Explanation below:

    1- Open the application - no problem
    2- Hit the add button - no problem
    3- Fill the boxes and then Hit the save button - no problem
    4- Hit Update button - no problem
    5- Fill any box to be updated and then Hit the save button - ERROR HERE....TYPE MISMATCH

    But, if i close the application re-open it and then hit the Update button, no error occur when saving the data.

    Hope some of you guys help me with this. My application is very similar to an example from the net (i mod it to fit my needs cuz i'm a noob for sure). After trying to debug my application i found that the example from the net have the same issue as mine, the code from the example is a lot smaller than mine so i think it will be easier to debug the original example. It is a flexgrid example and i'm using VB6 enterprise edition. If someone need the whole project just let me know to attach it here if is no problem with the forum rules.

    I put a not in the code where the problem appears to be. it is in the:
    Private Sub cmdSave_Click()


    Thanks to all!
    2005
    Attached Files Attached Files

  2. #2
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,974

    Re: flexgrid update problem

    We prefer it if you do upload the project (or at least the form as an .frm file), as it is easier to work with.

    In this case tho just showing un the appropriate code (as following) would be more appropriate:
    Code:
    '-----------------------------------------------------------------------------
    Private Sub cmdSave_Click()
    '-----------------------------------------------------------------------------
    
        Dim strPhone        As String
        Dim lngIDField      As Long
        Dim strSQL          As String
    
        If Not ValidateFormFields Then Exit Sub
        
        strPhone = txtArea.Text & txtPrfx.Text & txtLine.Text
        
        If mstrMaintMode = "ADD" Then
    ...
        Else
            lngIDField = CLng(grdCustomer.TextMatrix(mlngCustGridRow, 8))   >>> HERE IS THE PROBLEM
    ...
    The error "data type mismatch" means that you are trying to convert from one data type (String) to another (Long), but the data is not valid for that - it seems that the text in cell (mlngCustGridRow, 8) cannot be converted to a number.

    What I would recommend is to check the value is valid first, eg:
    Code:
        Else
    Dim strIDField as String
            strIDField = grdCustomer.TextMatrix(mlngCustGridRow, 8)
            If (strIDField = "") or Not(IsNumeric(strIDField)) Then
              MsgBox "Please set an ID value!"
              Exit Sub
            End If
            lngIDField = CLng(strIDField)
    ...

  3. #3
    Don't Panic! Ecniv's Avatar
    Join Date
    Nov 2000
    Location
    Amsterdam...
    Posts
    5,343

    Re: flexgrid update problem

    Type mis match is usually a problem for trying to store different types into a variable or field.

    Since you don't know which line it is at it is time you got to know vb6 debug bits.

    First on the first line of code in cmdSave
    (If Not ValidateFormFields Then Exit Sub)
    Put a breakpoint (to do this left click in the margin and a circle should appear. The line should also be highlighted.

    Now run your app. Click the buttons like you did, and when you get to the save bit the code should pop up and be highlighted (yellow I think was the default).

    From here you use f8 to step line by line through the code. If you hover over variables they should tell you what they are (values) or you can use ctrl+g to use the immediates window.


    Other alternative is to use error handling (read up on it...?)

    Code:
    'dim lines
    
    on error goto errh
    
    'your code here
    
    
    exit sub
    
    errh:
     resume next
    Put the break point on the resume next. If an error occurs this grabs it, the resume next moves to the next line of code after the error. You can then go back up one to find out where the error is....

    Post up if you get it more pinpointed.

    BOFH Now, BOFH Past, Information on duplicates

    Feeling like a fly on the inside of a closed window (Thunk!)
    If I post a lot, it is because I am bored at work! ;D Or stuck...
    * Anything I post can be only my opinion. Advice etc is up to you to persue...

  4. #4

    Thread Starter
    Hyperactive Member
    Join Date
    Aug 2005
    Posts
    261

    Re: flexgrid update problem

    si_the_geek, i have attached the project so that way you will see the data i'm trying to save/update. I have try with you suggestions but didn't worked at least in my end.

    I appreciate the help of both. Thanks.
    2005
    Attached Files Attached Files
    Last edited by 2005; Apr 10th, 2007 at 01:45 PM.

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

    Re: flexgrid update problem

    What resolution are you developing in?

    I can't even see the buttons.

  6. #6

    Thread Starter
    Hyperactive Member
    Join Date
    Aug 2005
    Posts
    261

    Re: flexgrid update problem

    ohh, i'm sorry i'm currently using 1920 by 1200, but 1280 by 1024 should work also. That was another question i was planning to do later, what resolution is the best for programming purposes for an app to be used on different computers. let me know if you need me to mod the UI for you to look at.

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

    Re: flexgrid update problem

    Ok, I ran it in 1280 by 1024 and I still saw no buttons (although I see the code for each button in the code window.)

  8. #8

    Thread Starter
    Hyperactive Member
    Join Date
    Aug 2005
    Posts
    261

    Re: flexgrid update problem

    should i move the buttons real quick and re-attach the project so you can run the app?

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

    Re: flexgrid update problem

    Type Mismatch errors are pretty common and generally speaking, pretty easy to fix, but in order to do so I would like to run your save routine, so at least that button should visible.

    On a completely unrelated note, who is going to be using this app? Will all your potential customers have this resolution problem or is this an internal application and all of the PCs in your company are running the same way?

  10. #10

    Thread Starter
    Hyperactive Member
    Join Date
    Aug 2005
    Posts
    261

    Re: flexgrid update problem

    Hack, i have re-attached the project in post number 4, now you should be able to see all the app at 1280 by 1024.

    Almost all pc's that will be using the app are running at 1280x1024, but that's something i will work cuz not 100% will be able to run it. At what resolution did you develop your app's?

    Let me know, thanks...

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

    Re: flexgrid update problem

    1024x768

  12. #12
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,974

    Re: flexgrid update problem

    You should generally develop apps in the lowest resolution that could possibly be used, and always allow your form(s) to work at any resolution/window size that the user has set - by moving/resizing controls appropriately. An explanation of how to do this can be seen in the "Forms" section of our Classic VB FAQs (link in my signature).

    Your Zip file is missing several files (.frm and .bas files), so it doesn't run at the moment.. and I'm not sure that I have the time to look at it properly myself.

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

    Re: flexgrid update problem

    You are blowing up on this line
    Code:
     lngIDField = CLng(grdProject.TextMatrix(mlngProjGridRow, 33))
    The first time through, it doesn't hit this line. The next time it does.

    TextMatrix is looking for text (I think.....I've not done much work with Flexgrids) and mlngProjGridRow is a number hence the Type Mismatch.

    Now, excuse me while I put my screen back to normal.

  14. #14
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,974

    Re: flexgrid update problem

    Your analysis is spot on.. similar to what I spotted in post #2.

    I'm not sure why the value in that column is not valid (presumably it is filled from somewhere else, but not being done 'properly' - which needs to be corrected), but the validation should be the same.

  15. #15

    Thread Starter
    Hyperactive Member
    Join Date
    Aug 2005
    Posts
    261

    Re: flexgrid update problem

    Post number 4 now should have all the nessesary files, sorry about that. Have many ppl here talking and talking. I think the only one working is me...

    What i don't understand is if i close the app and then re-open it, i can update any file in it without errors. Every time i hit update i should be hitting this code:

    lngIDField = CLng(grdProject.TextMatrix(mlngProjGridRow, 33))

    And why it gives error only if i add, save and then update?

    Thanks to both!

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

    Re: flexgrid update problem

    Put a break in the code and step through it to see what it is actually doing.

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