473,508 Members | 2,143 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 1762
On Mar 19, 12:11 pm, jlad...@gmail.com 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:

tblBrandProducts
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 frmBrandProducts 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_AfterUpdate()
If IsNull(txtKeyNum.Value) Then
If Not IsNull(cbxBrand.Value) Then
txtKeyNum.Value = Nz(DMax("[KeyNum]", "[tblBrandProducts]",
"[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 tblBrandProducts;

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********@FortuneJames.com

Mar 19 '07 #2

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

Similar topics

3
8783
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
3489
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...
2
2921
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...
1
1909
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...
1
6426
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...
3
9277
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...
4
4610
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
2829
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...
4
11190
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...
0
7124
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...
0
7385
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
7046
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...
0
7498
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5629
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
4707
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...
0
3195
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...
0
1558
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 ...
1
766
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.