473,387 Members | 1,483 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,387 software developers and data experts.

Referencing a query in VB

55
Hi all - I've been working on this from various angles for days, and I'm pretty well stumped at this point. Hope someone has some ideas. Working in Access 2000...

I’m trying to write code to assign a 3-part identifier to each new record.

The 3 parts are:
BidNumPt1: two-digit current year (BidNumPt1 = Format(Date, “yy”))
BidNumPt2: three-digit incremental number based on the year (Pt1) and the salesperson (Pt3)
BidNumPt3: one-digit code for each salesperson
(In the end, the concatenated bid number looks like 08007.3, for instance.)

I’m trying to figure out how to get the database to insert the next number for BidNumPt2.

I have a form (frmNewBids) based on qryBids, in which the salesperson puts data including his/her initials (that field is cboSales). I have Select Case code that assigns BidNumPt3 based on those initials (AfterUpdate on cboSales).

I have a separate query (qryAssignBidNum) that selects the maximum+1 value of tblBids.BidNumPt2 (a field I named Pt2Next) where BidNumPt1 = Format(Date(), “yy”), grouped by BidNumPt3.

First question: I can’t figure out how to call that field (qryAssignBidNum.Pt2Next) into the code for my form. The closest I’ve gotten is:

Expand|Select|Wrap|Line Numbers
  1. Private Sub Form_BeforeUpdate(Cancel As Integer)
  2.  
  3. If Me.NewRecord Then
  4.     If Me![txtBidNoPt1] = 0 Then
  5.         Me![txtBidNoPt1] = CStr(Format(Date, "yy"))
  6.     End If
  7. ‘BidNoPt2 has to be 3 digits, so I’m converting it to a string, adding two zeros to the beginning, and then taking the rightmost 3 characters.
  8.     If Me![txtBidNoPt2] = 0 Then
  9.         Me![txtBidNoPt2] = Right(CStr("00" & [Pt2Next]), 3)
  10.     End If
  11. End If
  12.  
  13. End Sub
I get an error msg “Variable not defined” on [Pt2Next] (line 9) -- or on [qryAssigBidNum] when I try:
Expand|Select|Wrap|Line Numbers
  1. Me![BidNoPt2] = Right(CStr("00" & [qryAssignBidNum].[Pt2Next]), 3)
Second question: I also need to add to line 9 the concept of “where qryAssignBidNum.BidNoPt3 = Me!txtBidNoPt3.”
Or maybe I need to put a parameter in qryAssignBidNum: BidNoPt3 = Forms!frmNewBids!txtBidNoPt3 ??
I doubt it will recognize the data in the new record before it’s saved, though…

This is all problem #1. Problem #2 will be how to assign BidNoPt2 when a) it’s the first bid of the year, or b) there’s a new salesperson (in other words, when BidNoPt3 has no corresponding data in qryAssignBidNum). But one thing at a time.

Angi
Jul 10 '08 #1
8 2163
ADezii
8,834 Expert 8TB
How about showing some sample data and corresponding Fields and Tables, and what the actual results would look like. It would then be much easier to assist you in arriving at a solution.
Jul 11 '08 #2
angi35
55
Certainly. Let's see if this helps:

In tblBids:
[Sales] [BidNumPt1] [BidNumPt2] [BidNumPt3]
AB 08 001 1
DG 08 001 2
NM 08 001 3
AB 08 002 1
DG 08 002 2
NM 08 002 3
DG 08 003 2
DG 08 004 2
NM 08 003 3

(sorry - I don't know if there's a way to get the columns to line up with their headers here, but I think you can get the idea anyway)

[Sales] = salesperson’s initials
[BidNumPt1] = 2-digit year of record creation; set as text field so that the 0 will appear at the beginning.
[BidNumPt2] = 3-digit increment; also set as text field because of the 0s on the left.
[BidNumPt3] = 1-digit code for the salesperson handling the bid; set as numeric field because I saw no reason to make it a text field.

The BidNum fields get concatenated in a view in forms and reports, such as: 08001.1; 08001.2; 08004.2

So each salesperson has his/her own series of numbers, distinguished by [BidNumPt3].

[BidNumPt2] starts over at 001 every year (for each salesperson/[BidNumPt3]).

When creating a new record in frmNewBids, the user selects/enters their initials in cboSales. This generates [BidNumPt3]. So, for instance, salesperson Doogie Goodman goes to a new record and inputs his initials DG, and then (as if by magic) [BidNumPt3] becomes "2".

[BidNumPt1] always equals the current two-digit year, so that's easy enough to set as a default value. (I've just figured this out and took out the If/Then code for control [txtBidNoPt1] on If Me.New Record... that you see in my earlier post.)

I've set the default value of [BidNumPt2] as 0 (it wouldn't accept 000) so that I can say
If Me.NewRecord Then
If Me![txtBidNoPt2] = 0 Then
...

I hope that helps. What more can I add?

Angi
Jul 11 '08 #3
ADezii
8,834 Expert 8TB
Certainly. Let's see if this helps:

In tblBids:
[Sales] [BidNumPt1] [BidNumPt2] [BidNumPt3]
AB 08 001 1
DG 08 001 2
NM 08 001 3
AB 08 002 1
DG 08 002 2
NM 08 002 3
DG 08 003 2
DG 08 004 2
NM 08 003 3

(sorry - I don't know if there's a way to get the columns to line up with their headers here, but I think you can get the idea anyway)

[Sales] = salesperson’s initials
[BidNumPt1] = 2-digit year of record creation; set as text field so that the 0 will appear at the beginning.
[BidNumPt2] = 3-digit increment; also set as text field because of the 0s on the left.
[BidNumPt3] = 1-digit code for the salesperson handling the bid; set as numeric field because I saw no reason to make it a text field.

The BidNum fields get concatenated in a view in forms and reports, such as: 08001.1; 08001.2; 08004.2

So each salesperson has his/her own series of numbers, distinguished by [BidNumPt3].

[BidNumPt2] starts over at 001 every year (for each salesperson/[BidNumPt3]).

When creating a new record in frmNewBids, the user selects/enters their initials in cboSales. This generates [BidNumPt3]. So, for instance, salesperson Doogie Goodman goes to a new record and inputs his initials DG, and then (as if by magic) [BidNumPt3] becomes "2".

[BidNumPt1] always equals the current two-digit year, so that's easy enough to set as a default value. (I've just figured this out and took out the If/Then code for control [txtBidNoPt1] on If Me.New Record... that you see in my earlier post.)

I've set the default value of [BidNumPt2] as 0 (it wouldn't accept 000) so that I can say
If Me.NewRecord Then
If Me![txtBidNoPt2] = 0 Then
...

I hope that helps. What more can I add?

Angi
Hello Angi, download my Test Database that I created for this Thread, and hopefully it will point you in the right direction. To post the code as well as relevant info would be confusing to say the least. Good luck and let me know how you make out.
Jul 11 '08 #4
angi35
55
Hello Angi, download my Test Database that I created for this Thread, and hopefully it will point you in the right direction. To post the code as well as relevant info would be confusing to say the least. Good luck and let me know how you make out.
Thanks ADezii! This is really helpful.

Angi
Jul 14 '08 #5
ADezii
8,834 Expert 8TB
Thanks ADezii! This is really helpful.

Angi
Glad we could help ya!
Jul 14 '08 #6
angi35
55
I have some follow-up questions and I want to attach the test database again, but I can't figure out how. Do I need some kind of permission from someone to attach a file?
Jul 15 '08 #7
ADezii
8,834 Expert 8TB
I have some follow-up questions and I want to attach the test database again, but I can't figure out how. Do I need some kind of permission from someone to attach a file?
Hello angi35. I'm going to send you my Private E-Mail Address in a Private Message. Send me an E-Mail with the Database in question attached, as well as any questions you may have. Please be as specific as possible as far as the questions and desired results are concerned. I'll get to the DB as soon as I get a chance.
Jul 15 '08 #8
ADezii
8,834 Expert 8TB
I have some follow-up questions and I want to attach the test database again, but I can't figure out how. Do I need some kind of permission from someone to attach a file?
Hello Angi, I'll be very busy for the next couple of days, but I did manage to make some changes to your DB. Download the Attachment, have a look, then get back to me. From now on in, let's keep all discussions in the Access Forum. Thanks.
Jul 16 '08 #9

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

Similar topics

2
by: sreddy | last post by:
I am trying to write a sql query on self referencing table. Just to brief ..Database is related to a Hiring department of the Qwest company. I need to generate a Report used by in HR...
1
by: sinthreck | last post by:
have a query which gets data from two tables. There's about 20 fields worth of data. In VB code, I run this query: strPOItems = "SELECT * FROM LEFT JOIN OutstandingInvoices ON (.PartNumber =...
2
by: Paul Cook | last post by:
Hi, I have three tables: Countries: ID Country States: ID
4
by: TWEB | last post by:
I think I may have an IIS / ASP.Net Configuration issue that I need some guidance with resolving. Here's the problem: a) I have a .stm file. b) I referenc a .aspx file on this .stm file using a...
2
by: Robin | last post by:
I have a main table that I need to delete records that arn't referenced in another. Query says I cannot delete. If I remove the reference query all deletes ok. Hope there is a way around this ?...
2
by: Axel | last post by:
Hi, a question about something that seems very simple at first glance: is it possible to reference other controls of a subform in a query window without referencing through the parent form? I...
2
by: ccsnavy | last post by:
For some reason referencing an unbound control on an active form from a query has ceased to work correctly. While other previously existing references to unbound controls in the same form seem to...
11
by: ozTinker | last post by:
I'm sure this shouldn't be too difficult, but I lack familiarity with the MS object model. Suppose I have a table "Purchase_Orders" and a form "TEMP" which I am using to look up a customer's...
3
by: DR | last post by:
I heard there is some trick to referencing statics in C# CLR stored procedure without having to mark the assembly as unsafe. Does anyone know this? This is usefull as the case of needing a little...
7
patjones
by: patjones | last post by:
Hi: I have two tables in my Access database, tblBase and tblRIP. Both of these tables have field names in common. The fields contain different data, but simply have the same names. For example,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
0
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
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,...
0
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...

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.