Results 1 to 22 of 22

Thread: Access question: Resolved

  1. #1

    Thread Starter
    Member
    Join Date
    May 2005
    Posts
    62

    Resolved Access question: Resolved

    I have a VB6 app that calls an access query.

    Inside the access query is a function that I have built in the access db.

    My problem is when I run the VB app the access VBA code editor opens and I have to step through the function to continue running the app.

    Does anybody know how to stop this?
    Last edited by primfran; Aug 3rd, 2005 at 12:46 PM. Reason: Resolved

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

    Re: Access question

    You could make a macro to run the vba function or procedure. Then in vb6 you can call the ...
    VB Code:
    1. DoCmd.RunMacro "MacroName", "RepeatCount", "RepeatExpression"
    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

  3. #3

    Thread Starter
    Member
    Join Date
    May 2005
    Posts
    62

    Re: Access question

    The function creates a value that is a condition in the query. Can a macro accomplish this?

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

    Re: Access question

    Macros can do allot of things. If you need to pass a value to a query that you are calling from vb then you may want to look into creating a parameter to pass to the query instead?
    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

  5. #5

    Thread Starter
    Member
    Join Date
    May 2005
    Posts
    62

    Re: Access question

    The query exports to a spreadsheet. The function gets the previous business day and uses that in the query. Nothing is passed from vb.

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

    Re: Access question

    That doesnt sound like it needs a function call to create a value then? It can all be done it the query except for the exporting. That could be done from a Macro and have the macro call the query first.
    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

  7. #7

    Thread Starter
    Member
    Join Date
    May 2005
    Posts
    62

    Re: Access question

    I am using DoCmd.TransferSpreadsheet to do the export.

    How would the query create the value if not by a function?

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

    Re: Access question

    You can change the query to a Make-Table query. Then the DoCmd.TransferSpreadsheet would use this new table to transfer.
    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

  9. #9

    Thread Starter
    Member
    Join Date
    May 2005
    Posts
    62

    Re: Access question

    Tried it and the vba editor still opens.

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

    Re: Access question

    Can you post your code?
    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

  11. #11

    Thread Starter
    Member
    Join Date
    May 2005
    Posts
    62

    Re: Access question

    Here is the code:


    oAccess.OpenCurrentDatabase "weekly dashboard.mdb"
    oAccess.DoCmd.TransferSpreadsheet acExport, acSpreadsheetTypeExcel9, "qryBuckets_Crosstab", wbBuckets
    oAccess.CloseCurrentDatabase


    Here is the query:

    SELECT Duration_H_weekend.Segment, Duration_H_weekend.FullName, Sum(Duration_H_weekend.[In Handl]) AS [SumOfIn Handl], Sum(Duration_H_weekend.[Total Duration]) AS [SumOfTotal Duration], Duration_H_weekend.Weekend
    FROM Duration_H_weekend INNER JOIN [ISA Table] ON Duration_H_weekend.[ACD EXT] = [ISA Table].[ACD EXT]
    GROUP BY Duration_H_weekend.Segment, Duration_H_weekend.FullName, Duration_H_weekend.Weekend
    HAVING (((Duration_H_weekend.Segment) Not Like "AYG" And (Duration_H_weekend.Segment) Not Like "TERM") AND ((Sum(Duration_H_weekend.[In Handl]))>0) AND ((Duration_H_weekend.Weekend)=getprevbusinessday(Date())));


    Here is the function called in the last line of the query:

    Public Function GetPrevBusinessDay(DayDate)
    If Format(DayDate, "ddd") = "Sun" Then
    GetPrevBusinessDay = DayDate - 2
    ElseIf Format(DayDate, "ddd") = "Mon" Then
    GetPrevBusinessDay = DayDate - 3
    Else
    GetPrevBusinessDay = DayDate - 1
    End If
    End Function



    Hope this helps, this is driving me nuts!!

  12. #12
    Fanatic Member dannymking's Avatar
    Join Date
    Jul 2005
    Location
    Darlington, North East UK
    Posts
    677

    Re: Access question

    Let me offer up my class module to export queries from external databases, and using SQL instead of defined queries...

    I have full instructions on another Forum... but I keep getting wrong for posting links to it in threads.. drop me a PM and I'll send you the link..

    To get you started.. and this is only a text based file.. you need to copy all the code into a new class module.. call your module something and then include reference's to both MS Excel and DAO..

    Then use code like..

    VB Code:
    1. Dim Exp As New clsExport 'or whatever you call it
    2.   With Exp
    3.     .DbName = "weekly dashboard.mdb"
    4.     .FileName = "Spreadsheet you are wanting exported to"
    5.     .SQL = "SELECT Duration_H_weekend.Segment, Duration_H_weekend.FullName, Sum(Duration_H_weekend.[In Handl]) AS [SumOfIn Handl], Sum(Duration_H_weekend.[Total Duration]) AS [SumOfTotal Duration], Duration_H_weekend.Weekend
    6. FROM Duration_H_weekend INNER JOIN [ISA Table] ON Duration_H_weekend.[ACD EXT] = [ISA Table].[ACD EXT]
    7. GROUP BY Duration_H_weekend.Segment, Duration_H_weekend.FullName, Duration_H_weekend.Weekend
    8. HAVING (((Duration_H_weekend.Segment) Not Like 'AYG' And (Duration_H_weekend.Segment) Not Like 'TERM') AND ((Sum(Duration_H_weekend.[In Handl]))>0) AND ((Duration_H_weekend.Weekend)=getprevbusinessday(Date())));"
    9.     .Export
    10.   End With

    I'll probably get wrong for suggesting pm'in the link to ya
    Attached Files Attached Files
    Danny

    Never Think Impossible

    If you find my answer helpful then please add to my reputation

  13. #13

    Thread Starter
    Member
    Join Date
    May 2005
    Posts
    62

    Re: Access question

    That seems like a lot of code to simply export a spreadsheet.

    I failed to mention in my post with the code that the query called from the app calls the query with the function in it. I don't know if that makes a difference.

    I tried using the macro, with no luck. It still opens the access vba editor.

  14. #14
    Fanatic Member dannymking's Avatar
    Join Date
    Jul 2005
    Location
    Darlington, North East UK
    Posts
    677

    Re: Access question

    It's a class module that prompts you for information and then supplies you with the output... Some of the advantages over TransferSpreadsheet are:

    using existing spreadsheets and saving them under a different name after export
    it will take a SELECT query's SQL rather than having to create the query then do the export...
    Browse function on Spreadsheets and Databases
    You can Transfer to Excel between databases..

    I know the code's a lot, but you don't need to worry about that all you need to do is change a few properties and it does the hard part for you..
    Danny

    Never Think Impossible

    If you find my answer helpful then please add to my reputation

  15. #15

    Thread Starter
    Member
    Join Date
    May 2005
    Posts
    62

    Re: Access question

    This class only allows a select statement.

    The query that needs to be exported is a crosstab query. The select query results are called by the crosstab.

  16. #16
    Fanatic Member dannymking's Avatar
    Join Date
    Jul 2005
    Location
    Darlington, North East UK
    Posts
    677

    Re: Access question

    It only allows a SELECT query, but it does also take the tablenames as well, in fact you can iterate through the tablename collection in the requested database and export either all of them or just a specific on..

    You could make table from the cross tab and then export the resulting table...
    Danny

    Never Think Impossible

    If you find my answer helpful then please add to my reputation

  17. #17

    Thread Starter
    Member
    Join Date
    May 2005
    Posts
    62

    Re: Access question

    That is my problem. When I make the table the code editor opens and I have to step throught the function that is part of the query to make the table.

  18. #18
    Fanatic Member dannymking's Avatar
    Join Date
    Jul 2005
    Location
    Darlington, North East UK
    Posts
    677

    Re: Access question

    And what is the actual code you are using to make the table..
    Danny

    Never Think Impossible

    If you find my answer helpful then please add to my reputation

  19. #19

    Thread Starter
    Member
    Join Date
    May 2005
    Posts
    62

    Re: Access question

    It is not code. It is a make table query in access.

  20. #20
    Fanatic Member dannymking's Avatar
    Join Date
    Jul 2005
    Location
    Darlington, North East UK
    Posts
    677

    Re: Access question

    Okay so there is a function built into the query.. ahh that'll be this then..

    VB Code:
    1. Public Function GetPrevBusinessDay(DayDate)
    2.   If Format(DayDate, "ddd") = "Sun" Then
    3.     GetPrevBusinessDay = DayDate - 2
    4.   ElseIf Format(DayDate, "ddd") = "Mon" Then
    5.     GetPrevBusinessDay = DayDate - 3
    6.   Else
    7.     GetPrevBusinessDay = DayDate - 1
    8.   End If
    9. End Function

    There is no return variable on this function and the parameter is not declared.. is this function really needed...

    Expr1: IIF(Format(DayDate,"ddd")="Sun",DateAdd("d",DayDate,-2),IIF(Format(DayDate,"ddd")="Mon",DateAdd("d",DayDate,-3),DateAdd("d",DayDate,-1)))

    Try that in your query.. change the daydate for the date field..
    Danny

    Never Think Impossible

    If you find my answer helpful then please add to my reputation

  21. #21

    Thread Starter
    Member
    Join Date
    May 2005
    Posts
    62

    Re: Access question: Resolved

    That worked. Thanks.

    Do you know if there is a setting in Access that will cause the code editor to open. There will be a need in the future to use a function and I would like to know if this is possible.

    Thanks again.

  22. #22
    Fanatic Member dannymking's Avatar
    Join Date
    Jul 2005
    Location
    Darlington, North East UK
    Posts
    677

    Re: Access question: Resolved

    place the word STOP at the begining of the procedure, when the code hits this line it will go into break mode.
    Danny

    Never Think Impossible

    If you find my answer helpful then please add to my reputation

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