473,326 Members | 2,127 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,326 software developers and data experts.

Trying to get VBA Code to Filter on the first two Digits of a Field

lcrutch
I have managed to get the following segment of code to gather information, from two tables (ItemINDEX, and ItemQOH) and export the results to an Excel file with a predefined name.

However, what I want to do is only export those Items that begin with "CX".

Expand|Select|Wrap|Line Numbers
  1. Private Sub Canwel_Export_Click()
  2. On Error Resume Next
  3. Dim QRY As DAO.QueryDef
  4. DoCmd.Hourglass True
  5. 'MsgBox fOSUserName, vbOKOnly
  6. DoCmd.SetWarnings False
  7. Set DB = CurrentDb
  8.  
  9. DoCmd.DeleteObject acQuery, "ITEM"
  10. strSQL = "SELECT ItemQOH.Item, ItemINDEX.CustNo, " _
  11. & "[ItemQOH]![Beg_Bal]+[ItemQOH]![QTY_IN]-[ItemQOH]![QTY_OUT] AS End_Bal " _
  12. & "FROM ItemINDEX INNER JOIN ItemQOH ON ItemINDEX.Item = ItemQOH.Item " _
  13. & "ORDER BY ItemQOH.Item;"
  14. 'MsgBox strSQL, vbOKOnly
  15. Set QRY = DB.CreateQueryDef("ITEM", strSQL)
  16. DoCmd.TransferSpreadsheet acExport, acSpreadsheetTypeExcel9, "ITEM", "C:\Documents and Settings\" _
  17. & "" & fOSUserName & "\My Documents\Canwel " _
  18. & "" & Year(Date) & " " & Month(Date) & " " & Day(Date) & ".xls", True
  19. Application.FollowHyperlink "C:\Documents and Settings\" _
  20. & "" & fOSUserName & "\My Documents\Canwel " _
  21. & "" & Year(Date) & " " & Month(Date) & " " & Day(Date) & ".xls", , , False
  22. Set QRY = Nothing
  23. DoCmd.DeleteObject acQuery, "ITEM"
Jul 29 '08 #1
2 2014
missinglinq
3,532 Expert 2GB
Have a look in Access Help at the Left() function.

Welcome to Bytes!

Linq ;0)>
Jul 29 '08 #2
Have a look in Access Help at the Left() function.

Welcome to Bytes!

Linq ;0)>
Thank you, that did the the trick!

And thank you for the welcome. :-)
Jul 30 '08 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: CSDunn | last post by:
Hello, I have a problem with field filtering between an Access 2000 Project form (the application is called CELDT), and the report that shows the results of the filter. Both the form and the...
2
by: Brian Newman | last post by:
I've got what is actually a triple-layer nested form. That part works fine. I've got the first subform related by the right key field to the main form, then I've got the second subform related to...
1
by: Daveyk0 | last post by:
Hello there, I have a front end database that I have recently made very many changes to to allow off-line use. I keep copies of the databases on my hard drive and link to them rather than the...
8
by: jquest | last post by:
Hi Again; I have had help from this group before and want to thank everyone, especially PCDatasheet. My database includes a field called HomePhone, it uses the (xxx)xxx-xxx format to include...
4
by: John Boy | last post by:
Hi, Can anyone help. This is really doing my nut in. 3 years ASP exp. and now doing .DOT which is a step in the wrong direction. Basically I am left with the code of a guy who has left. When I...
5
by: Ron S | last post by:
After days of searching I finally an example that would work with my application, the only problem is after entering all of the code it is not working. Would someone be kind enough to take a look at...
232
by: robert maas, see http://tinyurl.com/uh3t | last post by:
I'm working on examples of programming in several languages, all (except PHP) running under CGI so that I can show both the source files and the actually running of the examples online. The first...
5
by: DeanL | last post by:
Hi all, I'm trying to set up a query that runs from a command button on a form (simple enough so far), what I want the query to do is take values from the fields on the form (seven fields in...
8
by: Abedin | last post by:
I have 9 digits in form of "111020402". Then I have another 9 digits in form of "111020403". I have 100,000 records of these two 9-digit numbers. I want to filter this as follows: District:...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.