Modules & VBA :: Return Next Primary Key Value Which Is In Specific Format?
Jul 26, 2013
what is the best/cleanest way to return the next primary key value which is in the format yyyy-###.These are case files for the current year, ### being 3 digit number incremented by one for each new case.
I could use a function that finds the last one, checks the date, increments by one and returns it, but maybe I could use a public property or a class? I'm keen to use classes more for code maintenance.With a class then: would i create a PrimaryKey variable of the class type/object, so when I need a new key I would just type PrimaryKey.NewKey, for example?
I am trying to use a DLookup to search to find what block goes into the production of an item.
In a table called "dbo_vw_MCE_job_with_materials", each item contains a list of the parts which go into its production in a column titled "Expr1". However there are always more than one parts to this, with varying names.
What I am trying to do is to use a Dlookup to only return the first value which starts with B (as the block number is always the only part on the list which begins with B).
However I think as the item column contains the same item number in 8 columns, with different values in the Expr1 column, Dlookup only returns the top value "A-CF0057" (which is irrelevant as far as I am concered) - whereas I am hoping it will be able to pull the "B1499" value from the column as it is the only one starting with a B
Is there anyway to specify which value the dlookup function would return, or is there any way to apply some sort of permanent filter on my table?
I have an access table which has a key using letters (A,B,C,D...etc). Against each letter there is multiple rows against each letter. However for testing purposes I only need to get a single row against each key and I was wondering if there is a function I could use which would return only the first record of data for each key?
I have a simple UDF that takes a string and returns a variant, which is an array of strings Example Input "Brick Wall" Return value would be a variant array with first element "Brick" and and second element "Wall" Now I have a table with a field of strings, and I want to make a query that returns all the results from the function, one per line.
So if my input table looks like this
[strField] "kick the ball" "return the pass"
my query result should looks like this
[Orig] [new] "kick the ball" "kick" "kick the ball" "the" "kick the ball" "ball" "return the pass" "return" "return the pass" "the" "return the pass" "pass"
Last time I had to do something like this I used VBA exclusively, with ADO objects, but I thought a query based solution would be easier.
With my current data the largest return array size my function returns is 27 elements but I wouldn't want to rely on that number being fixed.
Having problems with the following function to goto a specific record and return a value from a field in that record.
Code:'Public Function intFieldZConv(strICAO As String) As IntegerPrivate Function intFieldZConv() As Integer 'TEST PURPOSE ONLYDim strICAO As String 'TEST PURPOSE ONLYstrICAO = "KTCM" 'TEST PURPOSE ONLYDim cnCurrent As ADODB.ConnectionDim rsFieldInfo As ADODB.RecordsetSet cnCurrent = CurrentProject.ConnectionSet rsFieldInfo = New ADODB.RecordsetrsFieldInfo.Open "tblFieldInfo", cnCurrent, , , adCmdTable'rsFieldInfo.Index = "FieldICAO"'rsFieldInfo.Seek "=", strICAOintFieldZConv = rsFieldInfo!FieldZConvSTMsgBox intFieldZConv 'TEST PURPOSE ONLYrsFieldInfo.ClosecnCurrent.CloseSet rsFieldInfo = NothingSet cnCurrent = NothingEnd Function
strICAO is received from another function which is to be used to determine the specific record in the table "tblFieldInfo". Once that record is referenced, the value from the field "FieldZConVST" is returned.
My problem area is highlighed (index and seek) which I receive an error stating "method or data member not found". Any help would be appreciated on how to finding a specific record.
I have a large table with millions of entries. I want to run a query to return all entries that are on a Saturday. The date stored in the table though is just typical date format eg 15/11/2015.
Is there a way I can format AutoNumber for a primary key, for example, have the first ID start as C001 then for the next entry Access will automatically go to C002, and so on and so forth?
SELECT Assets.* FROM Assets WHERE (((EXISTS (SELECT * FROM LCAMdump WHERE Assets.BarcodeNumber = LCAMdump.T_TAG )) =False)) OR (((EXISTS (SELECT * FROM LCAMdump WHERE ((SELECT BuildingName FROM Building_Names WHERE ASSETS.BuildingNameID = Building_Names.BuildingNameID)=LCAMdump.BUILDING) )) =False)) OR (((EXISTS (SELECT * FROM LCAMdump WHERE ((Assets.FLOOR)=[LCAMdump]![FLOOR]) )) =False)) OR (((EXISTS (SELECT * FROM LCAMdump WHERE ((Assets.DeskLocation)=[LCAMdump]![LOCATION_SEGMENT2]) )) =False)) OR (((EXISTS (SELECT * FROM LCAMdump WHERE ((Assets.BuildingLocation)=[LCAMdump]![LOCATION_SEGMENT1]) )) =False)) OR (((EXISTS (SELECT * FROM LCAMdump WHERE ((SELECT FirstName FROM Employees WHERE Assets.EmployeeID = Employees.EmployeeID)=LCAMdump.USER_FIRST) )) =False)) OR (((EXISTS (SELECT * FROM LCAMdump WHERE ((SELECT LastName FROM Employees WHERE Assets.EmployeeID = Employees.EmployeeID)=LCAMdump.USER_LAST) )) =False)) OR (((EXISTS (SELECT * FROM LCAMdump WHERE ((SELECT SSO FROM Employees WHERE Assets.EmployeeID = Employees.EmployeeID)=LCAMdump.LOGIN_SSO) )) =False)) OR (((EXISTS (SELECT * FROM LCAMdump WHERE ((SELECT UserID FROM Employees WHERE Assets.EmployeeID = Employees.EmployeeID)=LCAMdump.USER_LOGIN) )) =False));
It works great returns the correct results. But I don't need everything out of Assets. I just need a few things from there and a few things from 2 other tables.
I tried this but it now gives back over 220 repeating results.
SELECT Assets.BarcodeNumber , Employees.UserID , Building_names.BuildingName, Assets.Floor , Assets.BuildingLocation , Assets.DeskLocation , Employees.FirstName , Employees.LastName , Employees.SSO FROM Assets , Employees, Building_Names WHERE (((EXISTS (SELECT * FROM LCAMdump WHERE Assets.BarcodeNumber = LCAMdump.T_TAG )) =False)) OR (((EXISTS (SELECT * FROM LCAMdump WHERE ((SELECT BuildingName FROM Building_Names WHERE ASSETS.BuildingNameID = Building_Names.BuildingNameID)=LCAMdump.BUILDING) )) =False)) OR (((EXISTS (SELECT * FROM LCAMdump WHERE ((Assets.FLOOR)=[LCAMdump]![FLOOR]) )) =False)) OR (((EXISTS (SELECT * FROM LCAMdump WHERE ((Assets.DeskLocation)=[LCAMdump]![LOCATION_SEGMENT2]) )) =False)) OR (((EXISTS (SELECT * FROM LCAMdump WHERE ((Assets.BuildingLocation)=[LCAMdump]![LOCATION_SEGMENT1]) )) =False)) OR (((EXISTS (SELECT * FROM LCAMdump WHERE ((SELECT FirstName FROM Employees WHERE Assets.EmployeeID = Employees.EmployeeID)=LCAMdump.USER_FIRST) )) =False)) OR (((EXISTS (SELECT * FROM LCAMdump WHERE ((SELECT LastName FROM Employees WHERE Assets.EmployeeID = Employees.EmployeeID)=LCAMdump.USER_LAST) )) =False)) OR (((EXISTS (SELECT * FROM LCAMdump WHERE ((SELECT SSO FROM Employees WHERE Assets.EmployeeID = Employees.EmployeeID)=LCAMdump.LOGIN_SSO) )) =False)) OR (((EXISTS (SELECT * FROM LCAMdump WHERE ((SELECT UserID FROM Employees WHERE Assets.EmployeeID = Employees.EmployeeID)=LCAMdump.USER_LOGIN) )) =False));
I am sure it something simple but I am a novice at this so please help me. :D
I run a MakeTable Query on some data to COunt the number of records and Sum the Value of $$$ in a Currency field.The results produce a Number for the Count, but the SUM of the Balances is returned as text.
To get the SUM I use the expression SumBal: DSum("[Balance]","[XAM_data]").
Why it won't return the SumBal in Currency format?
My problem is that I am trying to update a field (called 'Sold' which is a yes/no checkbox column) for a specific record whenever an event is triggered. I have two forms (derived from two tables), one is called frmInventory and the other is called frmSales. In frmSales, I made a combo box called 'cboItemID' that allows the user to select from a list of items from my inventory table. Each selection from the list has 4 properties, the first of which is the 'Item ID' from the inventory table. Lastly, I have a field in both frmSales and frmInventory called 'Sold' as mentioned above. What I want to do is that whenever I check/uncheck the box in the 'Sold' field in frmSales, I want the 'Sold' field in frmInventory to check/uncheck as well, but only in the record with an 'Item ID' that matches the 'Item ID' from the combo box selection. In other words, I want to match the 'Sold' field in frmInventory with the 'Sold' field in frmSales, but for only the record that has the same 'Item ID' primary key as the one I picked from my selection in the combo box from frmSales.
how to reference another table and check whether or not it's 'Item ID' primary key is identical to the one I specified from the combo box, and then take action to update the 'Sold' field if the IDs match.
I was just wondering if this is a possibility to do in one query or if it has to be run from a number of different queries.
I am currently developing a database from scratch for work (with very little Access experience).
The current query I am trying to run, if linked to a number of tables with different information.
What I am trying to do primarily is link stock to a specific "Host Name", "Serial Number" and "Part Description".
In the "Host Name" there is for example - A1-TX10-10001, B1-TX2-10004, C1-TX-10004 - The latter part of the name is a unique identifier number. The first part is the compartment in which the "stock" sits. So you may have all three components (A1-TX1, B1-TX2, C1-TX3) linked to the same unique identifier (10001 for example)
The serial numbers naturally are different for every single one and of course the srial numbers are linked to the "Part Description" - which will read something like....."C1-TX3 Transmitter", "B1-TX2 Combiner" etc.....
When I run the query like this the Host Name (which is also linked to the unique identifier on its own (10001) it returns everything under "A1-TX1-10001"
What I would ideally like to do is write a statement so that if the "Part Description" contains "A1-TX1" it will only return rows that contain "A1-TX1" in the Host Name and the same for "B1-TX2" and "C1-TX3" in the same query.
If "Host Name" contains "A1-TX1" to return "Part Description" to contain "A1-TX1"
how to read a specific line in a CSV file (using VBA), to see if the phrase "There are no records available." is present.
If it is present, then I'm going to do a debug.print stating that there are no records to load - and then the script will move on to the next file. If the phrase isn't present, then I'm going to upload the file to Access, parse the information, and then upload it to a CRM. (I already have the latter portion of the code up and running....I just need to account for the first part, where I can determine if the file has data or not).
The structure of the file never changes. The first row is composed of eight column headers (Post Date, Card Number, Card Type, Auth Date, Batch Date, Reference Number, Reason, Amount) and (if) the phrase "There are no records available." is present, it will show up on the second row, in the first column (under Post Date).
I need to create an incrementing number to be used as a primary key in a table, based on a few variables. The format will be YYMM0000. It represents the number of units received each month.
I can come up with the formula to create that string no problem, but I need to create some code to check the table MAIN for the field TRACKER_ID to find the last number and increment it by 1.
i've created a database for city permits to be issued (which works perfectly thanx to alll your help), but now i need to be able to print out 1 permit at a time when it is issued (immediately after the data has been entered into the forms). i have 3 tables & 3 forms: contractors/owners, permtOrders (which has tabs for the different types of permits), and permitOrderDetails. the problem is the forms are set up for data entry (and only open in add mode for obvious reasons)...i need to be able to print an actual permit (like the carbon copy, landscape kind that usually tears out of a book). once the user enters the information into the forms, i need a little bit of that info from each form to be carried onto the actual printable permit. i'm not really sure how to accomplish this. :confused: i don't really know if i explained this right, but any suggestions are greatly appreciated.
I have a messagebox and want to know if it is possible that the messagebox give me a date as 15/01/2015 and not 15/01/2015. Using dailog box as messagebox
Code: Private Sub Save_Click() Dialog.Box "Tape # : " & Me.Tape & vbCrLf & "Sticker # : " & Me.Container1 & vbCrLf & "Book # : " & Me.Book & vbCrLf & "Date send Out : " & Me.DateSendOut & vbCrLf & "Date to be back : " & Me.DateToBeBack & vbCrLf & "OS : " & Me.System, , "Saving............." End Sub
I have a CSV file and want to convert it in a text format with some filtered data and with some formatting. This is an everyday task for me. So I made a table and imported the data in to it by the command :
Actually I have a column "SERIES", contains various series like "EQ", "BE", "DR", "BZ", "D1" and so on. And one more column with the dates having 4 / 5 current months dates and one next months date and one next to next month's date. And every date has got several thousand records.
now the issue is that : After importing these several thousand records, I want to export it but with a specific date and with a specific series.
The other thing is that, these dates change every month so if hard coded, the problem will occur the next month.
this code is working fine but when the month will change, the code won't work.
Can we have a date & series picker attached to this query, so it can export the records with the specified SERIES & DATE.
I tried putting a textbox on the form named TxtDate and in a Query ( Design mode ) under the date column, in criteria I have put [Forms]![Futures]![TxtDate] and after putting this line, the query becomes empty and no data is there.
I currently have this code to spit out some data into a table, however I would like to tweak it to be more of an append query. I know I need to use "INSERT INTO" somehow based on searching, but I also want to ensure the table doesn't get duplicate records in it from the previous code. Manually adding a primary key isn't an option as the table may be deleted.
Code: Public Function Output_RFC_Tables_Test() Dim Conn As ADODB.Connection Dim RS As New ADODB.Recordset
I am trying to search for a partial number in the primary key field. I have based my search off Allen Browne's search form [URL]
I have posted my full code below. I am having trouble with the portion searching the Member_ID field.
My first version:
I would get a Run-time error '3464':
Data type mismatch in criteria expression.
Code: If Not IsNull(Me.txtMember_ID) Then strWhere = strWhere & "([Member_ID] = """ & Me.txtMember_ID & """) AND " End If
My second Version: (I was searching for 54)
I would get a Run-time error '3075'
Syntax error (missing operator) in query expression '([Member_ID] = Like "*54*")'
Code: If Not IsNull(Me.txtMember_ID) Then strWhere = strWhere & "([Member_ID] = Like ""*" & Me.txtMember_ID & "*"") AND " End If
Version 3:
If I use this the search works when the Member_ID matches exactly
Code: If Not IsNull(Me.txtMember_ID) Then strWhere = strWhere & "([Member_ID] = " & Me.txtMember_ID & ") AND " End If
Code: Private Sub Member_Search_Click() 'Purpose: Build up the criteria string form the non-blank search boxes, and apply to the form's Filter. 'Notes: 1. We tack " AND " on the end of each condition so you can easily add more search boxes; _ we remove the trailing " AND " at the end. ' 2. The date range works like this: _ Both dates = only dates between (both inclusive. _ Start date only = all dates from this one onwards; _ End date only = all dates up to (and including this one).
I have an unbound textbox in a form which is filled with a text value eg "RWL" when the form opens. I now need another textbox that goes to the Company Data base finds the "RWL" text and finds its Primary key and puts it in the new textbox?
I got this function which is supposed to find a record based on the primary key, and then give three fields a value if they should be empty.
Public Function DoesXrefExist(faPersonID As Long, faRoleCode As String, faDorpID As Long, faDorpCode As String) If (DLookup("PersonID", "PEOPLE", "PersonID =" & faPersonID) > 0) Then End Function
Thats as far as i have got...for the next part.I get the feeling that i need to use the recordset object that exists somewhere.How do i access that recordset object? I have not been using any DAO or ADO, just straight VBA. I know i can create recordsets and stuff using DAO/ADO, but there must be a recordset that has been created already by the Dlookup command...