Results 1 to 10 of 10

Thread: [RESOLVED] VB6 & Access question

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Sep 2002
    Location
    southwest VA
    Posts
    136

    Resolved [RESOLVED] VB6 & Access question

    I am using VB6 and Access 97. My question is, is it possible inside a VB program to change the field attributes of a table in an Access database? For example, can I change a text field to number or number to text or change the format of the field or other such things?

  2. #2
    Frenzied Member DKenny's Avatar
    Join Date
    Sep 2005
    Location
    on the good ship oblivion..
    Posts
    1,171

    Re: VB6 & Access question

    Why would you ever want to change the DataType on a column as part of the normal operation of a database?
    Declan

    Don't forget to mark your Thread as resolved.
    Take a moment to rate posts that you think are helpful

  3. #3
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: VB6 & Access question

    Yes, you can do it but you may create an error is the data thats in the column is no longer valid for the destination data type. Are you sure this is what you want to do? and if so then how do you plan on invoking it?
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  4. #4

    Thread Starter
    Addicted Member
    Join Date
    Sep 2002
    Location
    southwest VA
    Posts
    136

    Re: VB6 & Access question

    Well, if you can tell me another solution I'm all ears. Here's my problem. I have a table in a database with an ID field (Stable_ID). I want to use this same database for both an active server page on my web site and a VB program I'm writing, so I don't have to have a bunch of seperate databases. The web page makes no changes, all it does is display what's in the table on the web page.

    When this field is set as Number, the web page no longer functions, but it works fine in the VB program. When I set it as Text, the web page works fine once more, but the VB program returns type mismatch errors.

    So, I thought if I could tell my program to change the field to Number, make whatever changes I need to in the program, then set it back to Text when done, I would be able to use the program for making changes, and still be able to import the database onto the web site for display. But if there's another way to do it so the web page AND the program both work, that's fine with me.

  5. #5
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: VB6 & Access question

    No offense but that is not a good solution for many reasons. It would be best to fix the issue by casting the data type to a valid type for one of the uses so no physical changes will be needing to be done/saved.

    Can you give more details on the issues for each problem?
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  6. #6

    Thread Starter
    Addicted Member
    Join Date
    Sep 2002
    Location
    southwest VA
    Posts
    136

    Re: VB6 & Access question

    Ok, if the field is set to type Number, the VB program works. If I set it to Text, VB gives me Runtime Error -2147217913 (80040e07): Data type mismatch in criteria expression. Which is the SQL statement:

    SQL = "Select * from Horses WHERE Stable_ID = " & SSID(Combo1.ListIndex) & " ORDER BY Horse_Name"

    Now, on the .asp page on the web site, if the field is set to text, everything works fine. If I set it to Number, then I get

    Microsoft OLE DB Provider for ODBC Drivers error '80040e07'

    [Microsoft][ODBC Microsoft Access Driver] Data type mismatch in criteria expression.

    /fhr/Stables/login_user.asp, line 72

    With the SQL statement:

    sql = "SELECT * FROM Stables INNER JOIN Horses ON Stables.Stable_ID = Horses.Stable_ID WHERE Stables.Stable_ID = '" & Num & "' ORDER BY Horses.Horse_Status, Horses.Horse_Year, Horses.Horse_Name"

    So, apparently ASP likes Text and VB likes Number and I don't know how to make them speak the same language.

  7. #7
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: VB6 & Access question

    The issue is that your not using the same WHERE clause. In the Vb program one you have
    VB Code:
    1. "WHERE Stable_ID = " & SSID(Combo1.ListIndex) & " ORDER BY Horse_Name"
    2.  
    3. 'And in the asp page you have...
    4. WHERE Stables.Stable_ID = '" & Num & "' ORDER BY Horses.Horse_Status, Horses.Horse_Year, Horses.Horse_Name"
    Note, the = sign on one has single quotes around the criteria value and the other where clause doesnt. This designates that one criteria is going to be a string or text value and the other is going to be numeric. If you change one of the where clauses criteria to no single quotes then they will work the same. If your adding records then the id should be numeric.
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  8. #8

    Thread Starter
    Addicted Member
    Join Date
    Sep 2002
    Location
    southwest VA
    Posts
    136

    Re: VB6 & Access question

    Well, I'll be darned!! I changed the asp page by taking out the quotes and changed the ID field to Number and it works!! Thank you!! I have had that stupid page set up that way for years now not knowing what was wrong with it, and now it works the way I originally wanted it to!

    You must be sick of seeing my posts by now, I'm sorry I've monopolized so much of your time today, but I really appreciate all your help!

  9. #9
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: VB6 & Access question

    No worries as I spend almost all day and night on the forums.

    I posted a reply in your other thread.

    Ps, dont forget to 'Resolve' your thread.
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  10. #10

    Thread Starter
    Addicted Member
    Join Date
    Sep 2002
    Location
    southwest VA
    Posts
    136

    Re: VB6 & Access question

    Ummm... how do I 'Resolve' it? (Feeling stupid now)

    Never mind, I found it!
    Last edited by Aelanna; Sep 27th, 2005 at 06:49 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
  •  



Click Here to Expand Forum to Full Width