473,660 Members | 2,459 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Joining different types Fields

Hi everybody! I´m new at this and I realize there´s a lot of great
and smart people, so let´s see if anybody knows how to do this.

I have a table where i need to combine 2 fields in another. That
resulting field will be the primary key.
I´ve seen some debates about this topics and i realize isn´t very
difficult but here comes the harder part (for me).
I need the second field to be an autoincrement field depending on the
first.
EXAMPLE:
Field 1: Brand (It could be A, B and C)
Field 2: Number (Will increment depending of the last value of the
brand)
Field 3: Brand-Number

If the last A brand introduced was BRAND A-3, Then when I select the A
brand to assing it to another register the "Number" field should
automatically display 4, and the "Brand-Number" field should display
"A-4".
DO U GET ME? Do u need me to be more specific at anything? LET ME
KNOW...

I hope one of u could please HELP ME!

Specific Questions:
- WHERE and WHAT do I have to write for the second field "Number" to
acomplish that behavior??
- WHERE and WHAT do I have to write for the Third Field "Brand-Number"
to join the information from fields 1 and 2??

Thanks in advance!

Mar 19 '07 #1
1 1776
On Mar 19, 12:11 pm, jlad...@gmail.c om wrote:
Hi everybody! I´m new at this and I realize there´s a lot of great
and smart people, so let´s see if anybody knows how to do this.

I have a table where i need to combine 2 fields in another. That
resulting field will be the primary key.
I´ve seen some debates about this topics and i realize isn´t very
difficult but here comes the harder part (for me).
I need the second field to be an autoincrement field depending on the
first.
EXAMPLE:
Field 1: Brand (It could be A, B and C)
Field 2: Number (Will increment depending of the last value of the
brand)
Field 3: Brand-Number

If the last A brand introduced was BRAND A-3, Then when I select the A
brand to assing it to another register the "Number" field should
automatically display 4, and the "Brand-Number" field should display
"A-4".
DO U GET ME? Do u need me to be more specific at anything? LET ME
KNOW...

I hope one of u could please HELP ME!

Specific Questions:
- WHERE and WHAT do I have to write for the second field "Number" to
acomplish that behavior??
- WHERE and WHAT do I have to write for the Third Field "Brand-Number"
to join the information from fields 1 and 2??

Thanks in advance!
Although my style is sometimes a bit unorthodox, I would do as
follows:

tblBrandProduct s
BPID AutoNumber (Primary Key)
Brand Text
KeyNum Long

Part of the reason for doing this is to avoid having a text field
become the primary key. Suppose you have a bound form to this table
called frmBrandProduct s with cbxBrand linked to Brand and txtKeyNum
linked to KeyNum. In the AfterUpdate event of the Brand combobox
(cbxBrand) you can set the KeyNum value as follows:

Private Sub cbxBrand_AfterU pdate()
If IsNull(txtKeyNu m.Value) Then
If Not IsNull(cbxBrand .Value) Then
txtKeyNum.Value = Nz(DMax("[KeyNum]", "[tblBrandProduct s]",
"[Brand] = " & Chr(34) & cbxBrand.Value & Chr(34)), 0) + 1
Else
txtKeyNum.Value = Null
End If
End If
End Sub

This will only affect new records since existing records already have
a KeyNum value.

I have a Rowsource for cbxBrand:
SELECT DISTINCT Brand FROM tblBrandProduct s;

When you move to a new record and select a brand, the appropriate
KeyNum will be calculated.

Whenever you need to display the Brand and KeyNum combination, such as
on a report, use:

[Brand] & "-" & [KeyNum]

For a search use:

WHERE [Brand] = "A" AND [KeyNum] = 3;

Breaking out the Brand and KeyNum values allows you to join on just
Brand or both Brand and KeyNum.

The purpose of the BrandKeyNum combination seems to be to help people
see a product's brand directly from the value. Access does not need
such assistance. One thing to watch out for is that deleted KeyNum
values are not reused unless the maximum KeyNum for a brand gets
deleted. If multiple users are adding products at the same time it
may be better to use the BrandKeyNum combination as a primary key so
that there is no chance of getting a duplicate BrandKeyNum combination
because two users try to create a new record for the same brand at the
same time. When doing it that way the form's BeforeUpdate event can
be used to check to see if the BrandkeyNum combination already exists
in the table so that a primary key error can only occur in rare
instances.

James A. Fortune
CD********@Fort uneJames.com

Mar 19 '07 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
8792
by: Ben Willcox | last post by:
Hi I am having difficulty writing an SQL query to do what I want: I have 1 table with 2 columns, 'id' and 'name': tbl_names: id name -- ---- 1 Bob 2 Jeff 3 Fred
2
3503
by: James | last post by:
Can anyone please shed some light on the following... I have a framework that uses dynamically created tables, named using an incremental "attribute set ID", as follows: attrdata_1 attrdata_2 attrdata_3 etc, etc...
2
2927
by: Shaggy Dragon | last post by:
Hi there, been looking for a solution to this for some time now. I've a UNION query that produces a table called AllSecurities: SELECT SecurityNumber, Book AS AllSecurities FROM Trades UNION SELECT SecurityNumber, Book from Positions; I'd really like to show is all the fields from the Positions table, but these don't exist in the Trades table, so they can't be included in the UNION (as far as I know). Is it possible to link this to a:
1
1916
by: Brian | last post by:
I need help joining info from two tables. Table1 and Table 2 have the same fields(Node,Card,Slot,Facility,Sub-Port,Channel,Group,Cic) Group is text, rest are number. Table 1 contains records for all possible combinations of Node,Card,Slot,Facility,Sub-Port,Channel which indicates a physical port on a piece of equipment. Table 2 is imported from a piece of equipment containing all above info that has an assigned Group and Cic. I want to...
1
6434
by: Steve C | last post by:
Hi, I'm having problems constructing a nested join. It's quite complex, so here's a simplfied example of the problem. Any thoughts on what I'm doig wrong - or if I've got the whole approach wrong are welcome. I've two tables :- one is a contact table contacting name, addresses etc. Three of the fields represent users - 'created by', 'last modified by' and 'owner'.
3
9291
by: Reader | last post by:
Hello all, I am joining two tables in a query and the output should be all those records where two fields in table1 match two corresponding fields in table2. I joined the tables using both fields in design view and the Select statement in SQL view looks good. The query runs perfectly and shows the result I want but when I save the query and close it, re-opening in design view shows the error message "Microsoft Office Access can't
4
4619
by: jason.teen | last post by:
Hi, when i am joining on a Column of Text Type with one of Memo type the resulting entry has funny chinese characters! Has anyone else encountered this before? Is there a cure?? Cheers.
3
2838
by: iht | last post by:
Say I have a database with types of car driven by people living in different cities. I made several queries to separate out the database according to city, then made queries to count out numbers of cars. So what I have now are queries those tally different car types in each city (simplified version): LAQuery 50 5 10 15 20 NYQuery
4
11197
by: herath | last post by:
Is there a way to join 2 tables where the 2 fields on which the tables joined are of different data types(char and varchar)?I tried with CONVERT but is does not give the desired output. My requirement is to get the minimum (earliest) Posted date along with two other fields.But when i join the two fields I get the duplicate records as well. Following is my query. ...
0
8428
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8341
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8851
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
8542
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
5650
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4177
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
2760
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
1984
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1740
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.