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

Formulate Index Value

418 256MB
I have developed a database for my CD collections. I am trying to develop serial number of each CD which will populate based on data entered in a form called frmCDDetails. This form is based on a table called tblCDDetails which combines data from various tables.

Table 1 tblMusicCategory
Field 1: MusicCategoryID - Auto Number (Primary)
Field 2: MusicCategory - text
Field 3: MusicCategoryAbbv - text

Each category is uniquely given 2-letter abbreviation. Examples, Easy Listening = EL, Jazz = JZ, Classical = CL, Country = CO

Table 2 tblArtists
Field 1 ArtistID - Auto Number (Primary)
Field 2 ArtistName - text
Field 3 ArtistAbbv - text

Each artist is given a 3-letter abbreviation to identify them. for example, John Denver is JDA, Julio Iglesias is JIB, Fran Sinatra FSC etc.

I want the serial number to read as XX.YYY.00.000.0000
XX = 2 letter from the category
YYY = 3 letter from the artist
00 = running number of CD for that artist
000 = running number for that category
0000 = running number for the entire collection.

Example: CO.JDA.10.030.0275

I
This means this CD is the 10th CD by John Denver. There are 30 CDs in Country Category and the Total CD collection is 275

I am trying to get this Serial number to be automatically populated when I select 1)MusicCategoryID and 2)ArtistID. In other words, as I select Country in the Category the text box for the Serial number will popualate as CO. and as I enter John Denver's name, the Serail number will populate as CO.JDA.10.030.0275

This is my goal.

So far I succeeded in creating the 2-letter Category part by using Choose function in a text box on the form frmCDDetails.

The rest I am struggling. For example, I couldn't get the Artist Abbreviation to display (instead the Artist ID number is displayed). Perhaps because ArtistID is not a part of the tblCDDetails but of a different table called tblArtists which is used for a subform and added to the frmCDDetails.

Can someone please help me with this?

Please remember I am a Novice and don't have much knowledge of VBA or specific functions unless it's explained with an example.

Many thanks to all the gurus out there. I am hoping one of you can help.
Aug 14 '08
176 8995
MNNovice
418 256MB
I will fix up the data and upload a modified version of the DB. We can proceed with our Automated Serial Number at that time.

Thank you for your wishes. Cheers.
Sep 30 '08 #101
NeoPa
32,556 Expert Mod 16PB
Sounds good. I look forward to it :)
Sep 30 '08 #102
MNNovice
418 256MB
Sounds good. I look forward to it :)
Hi, I am back from vacation. Hope all is well with you and your family.

I was able to read up on your comments and incorporated the instructions you sent me. Thank you.

Here is the updated Database. I corrected some bad data that existed. The new codes that you sent were applied. The serial number is getting updated automatically but there is a problem. Please look at records 584 – 589. I entered these as a sample data. When I entered the category and the artist’s name (record ID #588), the serial number automatically pops up as, UH.MHA.09.032.0588. Except for the first two digits everything else is correct. Same with record ID #589

Before entering record # 584, in my database I had 8 CDs for MHA in Category GH and 3 CDs in Category UH. When I entered 584 – 587 I didn’t get the correct numbers for MHA’s CD number in category UH. So I went to the tblCDDetails and manually corrected these numbers. Finally I entered record #588 & 589. See below for further details on the problem.
Expand|Select|Wrap|Line Numbers
  1. Record ID       What’s popping up  Correct Number should be
  2. 588             UH.MHA.09.032.0588    UH.MHA.08.032.0588
  3. 589             GH.MHA.10.023.0589    GH.MHA.09.023.0589
Apparently, it’s calculating MHA’s CDs for one category and not the other. So it’s mixing up UH with GH and giving me 09 followed by 10 and keeping it all under one category GH. How do we fix it? Did I explain it okay?

Thanks for your help.
Oct 8 '08 #103
MNNovice
418 256MB
I couldn't upload the zipped file. Network problem. I shall try in a few minutes. Thanks.
Oct 8 '08 #104
NeoPa
32,556 Expert Mod 16PB
As I look now, there is no attachment added :(

If you can get it added shortly I can look at it this evening when I go home :)
Oct 8 '08 #105
NeoPa
32,556 Expert Mod 16PB
How do we fix it? Did I explain it okay?
I won't KNOW the answers to these until I see the details and the database together.

However, I think the explanation is probably fine and the fix will be quite straightforward once in possession of all the info I need.

PS. Looking at the detail you've provided, I think the explanation seems fine :)
Oct 8 '08 #106
MNNovice
418 256MB
Please see post #104. I was able to upload the file. Many thanks.
Oct 8 '08 #107
NeoPa
32,556 Expert Mod 16PB
Great!

I'll download it this evening and delete it from the post when done.
Oct 8 '08 #108
NeoPa
32,556 Expert Mod 16PB
Attachment downloaded and removed.

Now to get to the fun part :D
Oct 8 '08 #109
NeoPa
32,556 Expert Mod 16PB
NB. When copying from the site at this time (it's a bit wrong with the code tags at the moment) remember to copy only from the source of a reply.

Otherwise, you get what is in your GetCDKey() function and that is a right royal mess :(

Don't worry for now, as I will probably be posting another version quite soon anyway, but when I do - be sure to include the indenting. It is very important if you ever want to work on it in future (and particularly if you want someone else to of course).
Oct 8 '08 #110
NeoPa
32,556 Expert Mod 16PB
You use the term Record ID in your post, yet there are two entities, a Record Number (Access has for all displayed recordsets) and a [Recording ID] which is the AutoNumber field in your table.

Anyway, I tried to follow your problem, but I found everything actually worked perfectly (according to the data that was there - I deleted some records at the end to match the recourd numbers you stated).

The largest value used for MHA was 08 and it produced UH.MHA.09.028.0584. The largest value for UH was 027.

I think if you clear up your data you will see it start to work properly for you. The data had some repeats in it, so the count of items didn't match the items used, but from the items used, it selected the correct new values.
Oct 8 '08 #111
NeoPa
32,556 Expert Mod 16PB
I did notice that the new record was added as soon as I left the [RecordingArtistID] control, so reordering the controls on the form wouldn't hurt (not very intuitive behaviour).

I will include in here the whole of the module as I have it (reformatted). It won't display well necessarily, but if you reply to the post then copy the code from within the quote, it should work for you.
Expand|Select|Wrap|Line Numbers
  1. Option Compare Database
  2. Option Explicit
  3.  
  4. Private Sub Form_Current()
  5.   With Me
  6.     If .NewRecord Then Call .RecordingTitle.SetFocus
  7.     .MusicCategoryID.Locked = Not .NewRecord
  8.     .RecordingArtistID.Locked = Not .NewRecord
  9.     .Duet_Trio.Locked = Not .NewRecord
  10.   End With
  11.  
  12. End Sub
  13.  
  14. Private Function GetCDKey() As String
  15.   Dim strCat As String, strArt As String, strVal As String
  16.   Dim intVal As Integer
  17.  
  18.   GetCDKey = ""
  19.   If IsNull(Me.MusicCategoryID) _
  20.   Or IsNull(Me.RecordingArtistID) Then Exit Function
  21.  
  22.   strCat = Me.MusicCategoryID.Column(2)
  23.   strArt = Me.RecordingArtistID.Column(2)
  24.   GetCDKey = "%C.%A.%2.%3.%4"
  25.   GetCDKey = Replace(GetCDKey, "%C", strCat)
  26.   GetCDKey = Replace(GetCDKey, "%A", strArt)
  27.   intVal = Val(Nz(DMax(Expr:="Mid([SerialNumber],8,2)", _
  28.                        Domain:="[tblCDDetails]", _
  29.                        Criteria:="[SerialNumber] Like " & _
  30.                                  "'*." & strArt & ".*'"), "0"))
  31.   GetCDKey = Replace(GetCDKey, "%2", Fmt(intVal + 1, 2))
  32.   intVal = Val(Nz(DMax(Expr:="Mid([SerialNumber],11,3)", _
  33.                        Domain:="[tblCDDetails]", _
  34.                        Criteria:="[SerialNumber] Like " & _
  35.                                  "'" & strCat & ".*'"), "0"))
  36.   GetCDKey = Replace(GetCDKey, "%3", Fmt(intVal + 1, 3))
  37.   intVal = Val(Nz(DMax(Expr:="Right([SerialNumber],4)", _
  38.                        Domain:="[tblCDDetails]"), "0"))
  39.   GetCDKey = Replace(GetCDKey, "%4", Fmt(intVal + 1, 4))
  40. End Function
  41.  
  42. Private Function Fmt(intVal As Integer, intDigits As String) As String
  43.   Fmt = Right(10000 + intVal, intDigits)
  44. End Function
  45.  
  46. Private Sub RecordingArtistID_AfterUpdate()
  47.   Me.TxtSerialNumber = GetCDKey()
  48. End Sub
  49.  
  50. Private Sub RecordingArtistID_NotInList(NewData As String, Response As Integer)
  51.     MsgBox "Double-click this field to add an entry to the list."
  52.     Response = acDataErrContinue
  53. End Sub
  54.  
  55. Private Sub RecordingArtistID_DblClick(Cancel As Integer)
  56. On Error GoTo Err_RecordingArtistID_DblClick
  57.     Dim lngRecordingArtistID As Long
  58.  
  59.     If IsNull(Me![RecordingArtistID]) Then
  60.         Me![RecordingArtistID].Text = ""
  61.     Else
  62.         lngRecordingArtistID = Me![RecordingArtistID]
  63.         Me![RecordingArtistID] = Null
  64.     End If
  65.     DoCmd.OpenForm "Artists", , , , , acDialog, "GotoNew"
  66.     Me![RecordingArtistID].Requery
  67.     If lngRecordingArtistID <> 0 Then Me![RecordingArtistID] = lngRecordingArtistID
  68.  
  69. Exit_RecordingArtistID_DblClick:
  70.     Exit Sub
  71.  
  72. Err_RecordingArtistID_DblClick:
  73.     MsgBox Err.Description
  74.     Resume Exit_RecordingArtistID_DblClick
  75. End Sub
  76.  
  77. Private Sub MusicCategoryID_AfterUpdate()
  78.   Me.TxtSerialNumber = GetCDKey()
  79. End Sub
  80.  
  81. Private Sub MusicCategoryID_NotInList(NewData As String, Response As Integer)
  82.     MsgBox "Double-click this field to add an entry to the list."
  83.     Response = acDataErrContinue
  84. End Sub
  85.  
  86. Private Sub MusicCategoryID_DblClick(Cancel As Integer)
  87. On Error GoTo Err_MusicCategoryID_DblClick
  88.     Dim lngRecordingArtistID As Long
  89.  
  90.     If IsNull(Me![MusicCategoryID]) Then
  91.         Me![MusicCategoryID].Text = ""
  92.     Else
  93.         lngRecordingArtistID = Me![MusicCategoryID]
  94.         Me![MusicCategoryID] = Null
  95.     End If
  96.     DoCmd.OpenForm "frmCategories", , , , , acDialog, "GotoNew"
  97.     Me![MusicCategoryID].Requery
  98.     If lngRecordingArtistID <> 0 Then Me![MusicCategoryID] = lngRecordingArtistID
  99.  
  100. Exit_MusicCategoryID_DblClick:
  101.     Exit Sub
  102.  
  103. Err_MusicCategoryID_DblClick:
  104.     MsgBox Err.Description
  105.     Resume Exit_MusicCategoryID_DblClick
  106. End Sub
  107.  
  108. Private Sub cmdAddSong_Click()
  109. On Error GoTo Err_cmdAddSong_Click
  110.  
  111.     Dim stDocName As String
  112.     Dim stLinkCriteria As String
  113.  
  114.     stDocName = "frmSongs"
  115.     DoCmd.OpenForm stDocName, , , stLinkCriteria
  116.  
  117. Exit_cmdAddSong_Click:
  118.     Exit Sub
  119.  
  120. Err_cmdAddSong_Click:
  121.     MsgBox Err.Description
  122.     Resume Exit_cmdAddSong_Click
  123.  
  124. End Sub
  125.  
  126. Private Sub cmdSave_Click()
  127. On Error GoTo Err_cmdSave_Click
  128.  
  129.     DoCmd.DoMenuItem acFormBar, acRecordsMenu, acSaveRecord, , acMenuVer70
  130.  
  131. Exit_cmdSave_Click:
  132.     Exit Sub
  133.  
  134. Err_cmdSave_Click:
  135.     MsgBox Err.Description
  136.     Resume Exit_cmdSave_Click
  137.  
  138. End Sub
  139.  
  140. Private Sub cmdFindCD_Click()
  141. On Error GoTo Err_cmdFindCD_Click
  142.  
  143.     Dim stDocName As String
  144.     Dim stLinkCriteria As String
  145.  
  146.     stDocName = "frmFIND"
  147.     DoCmd.OpenForm stDocName, , , stLinkCriteria
  148.  
  149. Exit_cmdFindCD_Click:
  150.     Exit Sub
  151.  
  152. Err_cmdFindCD_Click:
  153.     MsgBox Err.Description
  154.     Resume Exit_cmdFindCD_Click
  155.  
  156. End Sub
PS. I find I can copy this code accurately on FireFox 3. It may well work for you but check it does first. Indenting IS important.
Oct 8 '08 #112
NeoPa
32,556 Expert Mod 16PB
Last post for the night (probably).

I have a couple of queries I use when checking your data. They show me what SHOULD be used in the next record created (by showing the related records that already exist). Actually, they're both relatively simple :
Expand|Select|Wrap|Line Numbers
  1. SELECT tblCDDetails.*
  2. FROM tblCDDetails
  3. WHERE Left([SerialNumber],2)=[Enter Music Category Code (2 chars)]
Expand|Select|Wrap|Line Numbers
  1. SELECT tblCDDetails.*
  2. FROM tblCDDetails
  3. WHERE Mid([SerialNumber],4,3)=[Enter Artist Code (3 chars)]
Oct 9 '08 #113
MNNovice
418 256MB
You use the term Record ID in your post, yet there are two entities, a Record Number (Access has for all displayed recordsets) and a [Recording ID] which is the AutoNumber field in your table.

Anyway, I tried to follow your problem, but I found everything actually worked perfectly (according to the data that was there - I deleted some records at the end to match the recourd numbers you stated).

The largest value used for MHA was 08 and it produced UH.MHA.09.028.0584. The largest value for UH was 027.

I think if you clear up your data you will see it start to work properly for you. The data had some repeats in it, so the count of items didn't match the items used, but from the items used, it selected the correct new values.
By Record ID I meant Record Number. Sorry for the confusion. I will be more careful in using correct term(s).

Well, I am sorry to report it didn't work. please see the attached DB.

Record Numbers: 584 & 585 worked okay (both of these records were from category Ghazal (GH) for artist Mehdi Hassan (MHA). But when I selected Urdu/Hindi for the same artist, that's when it goofed up. For Record Number: 586 it generated: UH.MHA.11.028.0586 the correct serial number should be UH.MHA.04.028.0586.

For the next record I selected MHA in category GH. It popped a serial number that reads: GH.MHA.12.025.0587 when the correct number should be GH.MHA.11.025.0587

Because it is the 11th CD of Mehhi Hassan in Category Ghazal. 10th CD was Record Number 585.

Do you see what I am trying to explain?

In addition to the database I am attaching an Excel file. For a better visibility, Mehdi Hassan's CDs in these two categories (GH & UH) are highlighted in blue in this file.
Oct 9 '08 #114
MNNovice
418 256MB
Last post for the night (probably).

I have a couple of queries I use when checking your data. They show me what SHOULD be used in the next record created (by showing the related records that already exist). Actually, they're both relatively simple :
Expand|Select|Wrap|Line Numbers
  1. SELECT tblCDDetails.*
  2. FROM tblCDDetails
  3. WHERE Left([SerialNumber],2))=[Enter Music Category Code (2 chars)]
Expand|Select|Wrap|Line Numbers
  1. SELECT tblCDDetails.*
  2. FROM tblCDDetails
  3. WHERE Mid([SerialNumber],6,3))=[Enter Artist Code (3 chars)]
Perhaps it's stupid to ask this question, but where do these commands should be inserted? And also, I am not sure I quite understand the logic behind this change. Although I am positive and confident about your expertise. It's just for my own understanding :) Thanks.
Oct 9 '08 #115
MNNovice
418 256MB
I did notice that the new record was added as soon as I left the [RecordingArtistID] control, so reordering the controls on the form wouldn't hurt (not very intuitive behaviour).

I will include in here the whole of the module as I have it (reformatted). It won't display well necessarily, but if you reply to the post then copy the code from within the quote, it should work for you.
Expand|Select|Wrap|Line Numbers
  1. Option Compare Database
  2. Option Explicit
  3.  
  4. Private Sub Form_Current()
  5.   With Me
  6.     If .NewRecord Then Call .RecordingTitle.SetFocus
  7.     .MusicCategoryID.Locked = Not .NewRecord
  8.     .RecordingArtistID.Locked = Not .NewRecord
  9.     .Duet_Trio.Locked = Not .NewRecord
  10.   End With
  11.  
  12. End Sub
  13.  
  14. Private Function GetCDKey() As String
  15.   Dim strCat As String, strArt As String, strVal As String
  16.   Dim intVal As Integer
  17.  
  18.   GetCDKey = ""
  19.   If IsNull(Me.MusicCategoryID) _
  20.   Or IsNull(Me.RecordingArtistID) Then Exit Function
  21.  
  22.   strCat = Me.MusicCategoryID.Column(2)
  23.   strArt = Me.RecordingArtistID.Column(2)
  24.   GetCDKey = "%C.%A.%2.%3.%4"
  25.   GetCDKey = Replace(GetCDKey, "%C", strCat)
  26.   GetCDKey = Replace(GetCDKey, "%A", strArt)
  27.   intVal = Val(Nz(DMax(Expr:="Mid([SerialNumber],8,2)", _
  28.                        Domain:="[tblCDDetails]", _
  29.                        Criteria:="[SerialNumber] Like " & _
  30.                                  "'*." & strArt & ".*'"), "0"))
  31.   GetCDKey = Replace(GetCDKey, "%2", Fmt(intVal + 1, 2))
  32.   intVal = Val(Nz(DMax(Expr:="Mid([SerialNumber],11,3)", _
  33.                        Domain:="[tblCDDetails]", _
  34.                        Criteria:="[SerialNumber] Like " & _
  35.                                  "'" & strCat & ".*'"), "0"))
  36.   GetCDKey = Replace(GetCDKey, "%3", Fmt(intVal + 1, 3))
  37.   intVal = Val(Nz(DMax(Expr:="Right([SerialNumber],4)", _
  38.                        Domain:="[tblCDDetails]"), "0"))
  39.   GetCDKey = Replace(GetCDKey, "%4", Fmt(intVal + 1, 4))
  40. End Function
  41.  
  42. Private Function Fmt(intVal As Integer, intDigits As String) As String
  43.   Fmt = Right(10000 + intVal, intDigits)
  44. End Function
  45.  
  46. Private Sub RecordingArtistID_AfterUpdate()
  47.   Me.TxtSerialNumber = GetCDKey()
  48. End Sub
  49.  
  50. Private Sub RecordingArtistID_NotInList(NewData As String, Response As Integer)
  51.     MsgBox "Double-click this field to add an entry to the list."
  52.     Response = acDataErrContinue
  53. End Sub
  54.  
  55. Private Sub RecordingArtistID_DblClick(Cancel As Integer)
  56. On Error GoTo Err_RecordingArtistID_DblClick
  57.     Dim lngRecordingArtistID As Long
  58.  
  59.     If IsNull(Me![RecordingArtistID]) Then
  60.         Me![RecordingArtistID].Text = ""
  61.     Else
  62.         lngRecordingArtistID = Me![RecordingArtistID]
  63.         Me![RecordingArtistID] = Null
  64.     End If
  65.     DoCmd.OpenForm "Artists", , , , , acDialog, "GotoNew"
  66.     Me![RecordingArtistID].Requery
  67.     If lngRecordingArtistID <> 0 Then Me![RecordingArtistID] = lngRecordingArtistID
  68.  
  69. Exit_RecordingArtistID_DblClick:
  70.     Exit Sub
  71.  
  72. Err_RecordingArtistID_DblClick:
  73.     MsgBox Err.Description
  74.     Resume Exit_RecordingArtistID_DblClick
  75. End Sub
  76.  
  77. Private Sub MusicCategoryID_AfterUpdate()
  78.   Me.TxtSerialNumber = GetCDKey()
  79. End Sub
  80.  
  81. Private Sub MusicCategoryID_NotInList(NewData As String, Response As Integer)
  82.     MsgBox "Double-click this field to add an entry to the list."
  83.     Response = acDataErrContinue
  84. End Sub
  85.  
  86. Private Sub MusicCategoryID_DblClick(Cancel As Integer)
  87. On Error GoTo Err_MusicCategoryID_DblClick
  88.     Dim lngRecordingArtistID As Long
  89.  
  90.     If IsNull(Me![MusicCategoryID]) Then
  91.         Me![MusicCategoryID].Text = ""
  92.     Else
  93.         lngRecordingArtistID = Me![MusicCategoryID]
  94.         Me![MusicCategoryID] = Null
  95.     End If
  96.     DoCmd.OpenForm "frmCategories", , , , , acDialog, "GotoNew"
  97.     Me![MusicCategoryID].Requery
  98.     If lngRecordingArtistID <> 0 Then Me![MusicCategoryID] = lngRecordingArtistID
  99.  
  100. Exit_MusicCategoryID_DblClick:
  101.     Exit Sub
  102.  
  103. Err_MusicCategoryID_DblClick:
  104.     MsgBox Err.Description
  105.     Resume Exit_MusicCategoryID_DblClick
  106. End Sub
  107.  
  108. Private Sub cmdAddSong_Click()
  109. On Error GoTo Err_cmdAddSong_Click
  110.  
  111.     Dim stDocName As String
  112.     Dim stLinkCriteria As String
  113.  
  114.     stDocName = "frmSongs"
  115.     DoCmd.OpenForm stDocName, , , stLinkCriteria
  116.  
  117. Exit_cmdAddSong_Click:
  118.     Exit Sub
  119.  
  120. Err_cmdAddSong_Click:
  121.     MsgBox Err.Description
  122.     Resume Exit_cmdAddSong_Click
  123.  
  124. End Sub
  125.  
  126. Private Sub cmdSave_Click()
  127. On Error GoTo Err_cmdSave_Click
  128.  
  129.     DoCmd.DoMenuItem acFormBar, acRecordsMenu, acSaveRecord, , acMenuVer70
  130.  
  131. Exit_cmdSave_Click:
  132.     Exit Sub
  133.  
  134. Err_cmdSave_Click:
  135.     MsgBox Err.Description
  136.     Resume Exit_cmdSave_Click
  137.  
  138. End Sub
  139.  
  140. Private Sub cmdFindCD_Click()
  141. On Error GoTo Err_cmdFindCD_Click
  142.  
  143.     Dim stDocName As String
  144.     Dim stLinkCriteria As String
  145.  
  146.     stDocName = "frmFIND"
  147.     DoCmd.OpenForm stDocName, , , stLinkCriteria
  148.  
  149. Exit_cmdFindCD_Click:
  150.     Exit Sub
  151.  
  152. Err_cmdFindCD_Click:
  153.     MsgBox Err.Description
  154.     Resume Exit_cmdFindCD_Click
  155.  
  156. End Sub
PS. I find I can copy this code accurately on FireFox 3. It may well work for you but check it does first. Indenting IS important.
Copied as instructed. Thanks.
Oct 9 '08 #116
NeoPa
32,556 Expert Mod 16PB
Perhaps it's stupid to ask this question, but where do these commands should be inserted? And also, I am not sure I quite understand the logic behind this change. Although I am positive and confident about your expertise. It's just for my own understanding :) Thanks.
Not at all.

This is fairly straightforward though. Once you've done it a couple of times you will easily be able to switch between Design View of an Access QueryDef and SQL view.

It seems that mostly, we have been looking at Access VBA issues in this thread, but it's common also to deal with queries (QueryDefs). An Access query, while it is generally displayed in Design View to modify, can also be shown in SQL View (Every QueryDef has a set of SQL behind the scenes).

When a QueryDef is shown in SQL View it is possible to copy and/or paste SQL code (as I posted in #113) into or from it. If you create a new query, then switch to SQL View (View / SQL) you can paste in the SQL posted. If you then change to Design View (View / Design) you will see it in Design View in the normal way.

Let me know how you get on with this.
Oct 9 '08 #117
MNNovice
418 256MB
Well, this much I understood. That you created a couple of queries to look into my data. These queries are displayed in SQL view in post 113. I don't have to add these commands, queries anywhere. Right?

I am awaiting your response to my post #114. Thanks.
Oct 9 '08 #118
NeoPa
32,556 Expert Mod 16PB
Well, this much I understood. That you created a couple of queries to look into my data. These queries are displayed in SQL view in post 113. I don't have to add these commands, queries anywhere. Right?
I run these queries while I am looking at the values that are produced in the [SerialNumber] field. With all the matching records visible in the query, I can work out for myself what the code SHOULD be producing and compare that with what it does produce.

Remember, it is not the count but the Max() that we're looking for. In an ideal world (database) they would be the same, but while the data is not all properly cleaned up yet, there are discrepancies. These queries help to see what the code should be producing.
Oct 9 '08 #119
NeoPa
32,556 Expert Mod 16PB
I am awaiting your response to my post #114. Thanks.
I will get to this. As you know I can only look at your database at home. I have just got home but I have to go out again this evening (shortly), so I will attempt to make some time later. It's not always possible to catch up with all my threads every day I'm afraid, but I do try.

I certainly have the two latest attachments downloaded now at least.
Oct 9 '08 #120
NeoPa
32,556 Expert Mod 16PB
I find I'm too tired to work tonight. I will have a more in-depth look at exactly what's happening with the database tomorrow or over the weekend when I can. Sorry for the extra delay.
Oct 9 '08 #121
NeoPa
32,556 Expert Mod 16PB
Record Numbers: 584 & 585 worked okay (both of these records were from category Ghazal (GH) for artist Mehdi Hassan (MHA). But when I selected Urdu/Hindi for the same artist, that's when it goofed up. For Record Number: 586 it generated: UH.MHA.11.028.0586 the correct serial number should be UH.MHA.04.028.0586.
This seems wrong.

.04. would imply that there were only three previous CDs by Mehdi Hassan. This can't be true as you have just added the tenth in record number 585.

PS. I will investigate further - but I think this is a fundamental problem.
Oct 10 '08 #122
NeoPa
32,556 Expert Mod 16PB
I tried to use the SQL I posted in post #115 - BUT THEY BOTH FAILED!!

Sorry that was so poor. I've fixed them both now and 'now' they both work fine.

PS. You may get a better idea of how they can help, now you can see them working correctly.
Oct 10 '08 #123
NeoPa
32,556 Expert Mod 16PB
I want the serial number to read as XX.YYY.00.000.0000
XX = 2 letter from the category
YYY = 3 letter from the artist
00 = running number of CD for that artist
000 = running number for that category
0000 = running number for the entire collection.
Record Numbers: 584 & 585 worked okay (both of these records were from category Ghazal (GH) for artist Mehdi Hassan (MHA). But when I selected Urdu/Hindi for the same artist, that's when it goofed up. For Record Number: 586 it generated: UH.MHA.11.028.0586 the correct serial number should be UH.MHA.04.028.0586.
From your post #114 (the part quoted in post #122), and from looking at the data you're referring to, it seems to me that maybe you don't want the third part of the Serial Number to be "00 = running number of CD for that artist", but instead you want it to be "00 = running number of CD for that artist WITHIN THE SELECTED CATEGORY". Is that right?
Oct 10 '08 #124
MNNovice
418 256MB
From your post #114 (the part quoted in post #122), and from looking at the data you're referring to, it seems to me that maybe you don't want the third part of the Serial Number to be "00 = running number of CD for that artist", but instead you want it to be "00 = running number of CD for that artist WITHIN THE SELECTED CATEGORY". Is that right?
Sorry I was too busy this weekend to read through all your comments. I will shortly do so.

You are too cool. You are absolutely correct. I want "00 = running number of CD for a given artist within the selected category".
Oct 12 '08 #125
NeoPa
32,556 Expert Mod 16PB
No worries about busy-ness :)

I will look at the code in this fresh light. It might be a little more complicated, but it can certainly be done.

I will post further when I've had a chance to look into it.
Oct 12 '08 #126
NeoPa
32,556 Expert Mod 16PB
Try the following version of the function :
Expand|Select|Wrap|Line Numbers
  1. Private Function GetCDKey() As String
  2.   Dim strCat As String, strArt As String, strVal As String
  3.   Dim intVal As Integer
  4.  
  5.   GetCDKey = ""
  6.   If IsNull(Me.MusicCategoryID) _
  7.   Or IsNull(Me.RecordingArtistID) Then Exit Function
  8.  
  9.   strCat = Me.MusicCategoryID.Column(2)
  10.   strArt = Me.RecordingArtistID.Column(2)
  11.   GetCDKey = "%C.%A.%2.%3.%4"
  12.   GetCDKey = Replace(GetCDKey, "%C", strCat)
  13.   GetCDKey = Replace(GetCDKey, "%A", strArt)
  14.   strArt = strCat & "." & strArt
  15.   intVal = Val(Nz(DMax(Expr:="Mid([SerialNumber],8,2)", _
  16.                        Domain:="[tblCDDetails]", _
  17.                        Criteria:="[SerialNumber] Like " & _
  18.                                  "'" & strArt & ".*'"), "0"))
  19.   GetCDKey = Replace(GetCDKey, "%2", Fmt(intVal + 1, 2))
  20.   intVal = Val(Nz(DMax(Expr:="Mid([SerialNumber],11,3)", _
  21.                        Domain:="[tblCDDetails]", _
  22.                        Criteria:="[SerialNumber] Like " & _
  23.                                  "'" & strCat & ".*'"), "0"))
  24.   GetCDKey = Replace(GetCDKey, "%3", Fmt(intVal + 1, 3))
  25.   intVal = Val(Nz(DMax(Expr:="Right([SerialNumber],4)", _
  26.                        Domain:="[tblCDDetails]"), "0"))
  27.   GetCDKey = Replace(GetCDKey, "%4", Fmt(intVal + 1, 4))
  28. End Function
Oct 12 '08 #127
MNNovice
418 256MB
[quote]
Try the following version of the function :
This is just too good to be true. You are a genius! I guess you already know that. How can I ever put into words how thankful I am for your generous helping hands! Please accept my sincere gratitudes for your time and effort. I am grateful.

Can we talk about my next problem? It's rather a simple one.

On frmCDDetails, when I double click on [SongTitleID] on sfrmCDDetails to add a new song, I get this error message: "You tried to assign the Null Value to a variable that is not a variant data type". I don't understand what does this mean.

So I added a command button: ADD NEW Song which opens the form to add a new song. But I need to close the form frmCDDetails in order for the new song to show up on the dropdown list. This is so inefficient.

How can I solve this problem?

Once again many thanks for your help. It's much appreciated.
Oct 13 '08 #128
NeoPa
32,556 Expert Mod 16PB
Instead of closing and re-opening the form, try a call of {form reference}.ReQuery.
Oct 13 '08 #129
MNNovice
418 256MB
Instead of closing and re-opening the form, try a call of {form reference}.ReQuery.
Well, I thought that's what I did. But it does not work. Here are my codes:

Expand|Select|Wrap|Line Numbers
  1. Private Sub ArtistID_NotInList(NewData As String, Response As Integer)
  2. MsgBox "Double-click this field to add an entry to the list."
  3.     Response = acDataErrContinue
  4.  
  5. End Sub
  6.  
  7. Private Sub SongTitleID_DblClick(Cancel As Integer)
  8. On Error GoTo Err_SongTitleID_DblClick
  9.     Dim lngSongID As Long
  10.  
  11.     If IsNull(Me![SongTitleID]) Then
  12.         Me![SongTitleID].Text = ""
  13.     Else
  14.         lngSongTitleID = Me![SongTitleID]
  15.         Me![SongTitleID] = Null
  16.     End If
  17.     DoCmd.OpenForm "frmSongs", , , , , acDialog, "GotoNew"
  18.     Me![SongTitleID].Requery
  19.     If lngSongTitleID <> 0 Then Me![SongTitleID] = lngSongTitleID
  20.  
  21. Exit_SongTitleID_DblClick:
  22.     Exit Sub
  23.  
  24. Err_SongTitleID_DblClick:
  25.     MsgBox Err.Description
  26.     Resume Exit_SongTitleID_DblClick
  27. End Sub
  28.  
  29. Private Sub SongTitleID_NotInList(NewData As String, Response As Integer)
  30. MsgBox "Double-click this field to add an entry to the list."
  31.     Response = acDataErrContinue
  32. End Sub

It's in a sub form (sfrmCDDetails) within the the frmCDDetails. Field name: [SongTitleID].

I have exactly the same codes for updating MusicCategoryID and it works just fine. What am I doing wrong here?

Thanks.
Oct 13 '08 #130
NeoPa
32,556 Expert Mod 16PB
Let me throw the question back at you.

Is it line #18 you're talking about?

Exactly what are you trying to update on the screen? Which object? Is it a control - or a form?
Oct 13 '08 #131
MNNovice
418 256MB
May be I didn't quite explain my problem clearly. Sorry about that.

frmCDDetails is used to enter/update CDs. Within this Form I have a subform called sfrmCDDetails. When I add/update a CD, I use this subform to enter Track No., Song Title, Artists etc.

There is another form called frmSongs based on a table called tblSongs that lists songs of all kinds. When I am using sfrm to enter/update tracks of a CD, if a song does not exist in my list (ie., tblSongs), I would like to call/open frmSongs, add the song to the list and continue with my data entry on frmCDDetails and/or sfrmCDDetails. My objective is to update tblSongs so that the new song now appears in the dropdown list on the sfrmCDDetails without my exiting the frmCDDetails.

Does this make sense? Thanks.
Oct 13 '08 #132
NeoPa
32,556 Expert Mod 16PB
It does make sense, but it is also harder for me to work with than simple answers to the questions. Let me explain as I'm not trying to be snappy.

A textual description / explanation is all very well, but to process it I have to read it all and try and fit the information into my mental picture. As it covers such a large area, my picture has to be large too, so I have to consider many angles, even though a lot of it is irrelevant to the problem.

Knowing which object (form or control) is the one that needs to be updated and the current attempt is at line #18 allows me to focus on a much smaller set of information, so I have a much smaller, more focused picture. That makes finding an answer so much simpler as I have much less elements to worry about fitting together.

Anyway, if you could confirm the piece of code you you are talking about is around line #18 and what the name of the control is (I now know it's a ComboBox control but I still don't have the name of it), then I can see what I can do to help.
Oct 13 '08 #133
MNNovice
418 256MB
It does make sense, but it is also harder for me to work with than simple answers to the questions. Let me explain as I'm not trying to be snappy.

Anyway, if you could confirm the piece of code you you are talking about is around line #18 and what the name of the control is (I now know it's a ComboBox control but I still don't have the name of it), then I can see what I can do to help.
The combo box is called [SongTitleID] and yes, it's line #18. Sorry for not knowing what's being asked. I shall be more succinct next time.

Also, I should probably open a new thread for this question, should I? Thanks.
Oct 13 '08 #134
NeoPa
32,556 Expert Mod 16PB
The combo box is called [SongTitleID] and yes, it's line #18. Sorry for not knowing what's being asked. I shall be more succinct next time.
No worries. It wasn't obvious.
Also, I should probably open a new thread for this question, should I? Thanks.
You can, but I'm happy to deal with this here if you are. It's already nearly 140 posts long so as far as Googling is concerned - I doubt anyone will want to wade through it all even if they were to find it.

Besides, it's not a typical question that others are likely to be asking. It's quite specific to your particular database.
Oct 13 '08 #135
NeoPa
32,556 Expert Mod 16PB
The combo box is called [SongTitleID] and yes, it's line #18.
It is now clear that the problem is not the code as such - but the order (or timing) of when the code is run.

When you open a new form, the code after the OpenForm runs immediately afterwards. It is not synchronous so it doesn't wait for the form to close before continuing. This means that the requery is done before any changes are made via the form.

What you need to do is to call the Requery from the code in the opened form, as it closes. You can pass the name of the form and / or control to the new form using OpenArgs if necessary.

Does that make sense?
Oct 13 '08 #136
MNNovice
418 256MB
What you need to do is to call the Requery from the code in the opened form, as it closes. You can pass the name of the form and / or control to the new form using OpenArgs if necessary.

Does that make sense?
Sorry but this is way over my expertise/understanding of SQL. I applied similar codes (in the same order) to update Artists and Categories and those two combo boxes are working just fine namely, [RecordingArtistID] and [MusicCategoryID]. Why it does not work for [SongTitleID] - that I don't understand.

Thanks.
Oct 14 '08 #137
NeoPa
32,556 Expert Mod 16PB
To answer that I would need to see the other code. I suspect it's different in some way that's not obvious to you. Maybe doesn't use a separate form to enter the new item. I don't know until I get to see the database with the problem in it. Certainly, your code for this I would NOT expect to work for the reasons outlined.

To explain again, more simply if I can, the requery, if it's to have the desired effect, needs to execute after the item is added on the form.

As the requery code is immediately after the code which opens the form, it is run immediately after the form is opened, and not after the item has been added on the form.

Let's have another copy of the database and we'll see what we can discover.
Oct 14 '08 #138
NeoPa
32,556 Expert Mod 16PB
I should say I'm not in Wednesday evening and tonight might also be a little tight. I will do what I can if you post the database but it may not get done until Thursday. Obviously I'll do what I can though :)
Oct 14 '08 #139
MNNovice
418 256MB
To answer that I would need to see the other code. I suspect it's different in some way that's not obvious to you. Maybe doesn't use a separate form to enter the new item. I don't know until I get to see the database with the problem in it. Certainly, your code for this I would NOT expect to work for the reasons outlined.

To explain again, more simply if I can, the requery, if it's to have the desired effect, needs to execute after the item is added on the form.

As the requery code is immediately after the code which opens the form, it is run immediately after the form is opened, and not after the item has been added on the form.

Let's have another copy of the database and we'll see what we can discover.
Here is what I am trying to achieve.

I opened the form frmCDDetails to add a new CD. The page for Record 584 opened. I entered a CD titled "The Gold Collection Vol 1" by Karen Carpenters. Now I would like to enter the track info for this CD. For example, a track titled: "Close to you" But this song is not listed in tblSongs and therefore does not show up in the drop down list. So in order to enter the track info, I would like to click on [SongTitleID] (located in the subform sfrmCDDetails). But when I double click on this combo box [SongTitleID], I get the error message I explained earlier.

** Edit **
On frmCDDetails, when I double click on [SongTitleID] on sfrmCDDetails to add a new song, I get this error message: "You tried to assign the Null Value to a variable that is not a variant data type". I don't understand what does this mean.
** /Edit **


However, on the same page of this form frmCDDetails, I can add a new Music Category or a new Artist's name by double clicking the combo boxes, [MusicCategoryID] and [RecordingArtistID] respectively.

Hope this explains my problem. Looking forward to your solutions, whenever you have time.

As always, thank you very much.
Oct 14 '08 #140
NeoPa
32,556 Expert Mod 16PB
Database downloaded.

Will update when I get time to look at it.
Oct 14 '08 #141
NeoPa
32,556 Expert Mod 16PB
I leave this for two days and then I have to search pages of threads to find it again.

Just to let you know I'm looking at it now. Hope to post something soon.
Oct 16 '08 #142
MNNovice
418 256MB
No hurry. Take your time. Let me know if you have any questions.

I will be leaving for Iowa for the weekend. Shall return Sunday. And thank you for your help. Hope you get some time off to enjoy with family and friends.

Take care.
Oct 16 '08 #143
NeoPa
32,556 Expert Mod 16PB
Please check your PMs and let me know your response.
Oct 16 '08 #144
NeoPa
32,556 Expert Mod 16PB
I've just noticed (after working through some of the code) that line #17 of post #130 includes a parameter (acDialog) which means that my post #136 is not correct. Please disregard it.
Oct 16 '08 #145
NeoPa
32,556 Expert Mod 16PB
Expand|Select|Wrap|Line Numbers
  1. If IsNull(Me![SongTitleID]) Then
  2.     Me![SongTitleID].Text = ""
  3. Else
  4.     lngSongTitleID = Me![SongTitleID]
  5.     Me![SongTitleID] = Null
  6. End If
This is the code in your procedure where the error occurs (Line #5). I did have a fair look to see if I could see why this crashes when the same (similar) code for Artist doesn't have the same problem, but I couldn't find it easily, and I didn't want to spend too much more time on it as removing line #5 (Me![SongTitleID] = Null) seems to fix the problem. I can't see any reason for that line, but if there is one just tell me. If not, simply lose it. It does work without it as far as I can see.
Oct 16 '08 #146
NeoPa
32,556 Expert Mod 16PB
I've found out why you can't delete line #5 :(

I'm struggling to understand why the control [SongTitleID] behaves so differently from the others. I think I will need to get back to this at some other time.

I've checked through the way the different (one working & one not) controls are set up and even back to the queries and tables they come from. While there are some minor differences, I can't see anything which points to why.
Oct 16 '08 #147
MNNovice
418 256MB
I've found out why you can't delete line #5 :(

I'm struggling to understand why the control [SongTitleID] behaves so differently from the others. I think I will need to get back to this at some other time.

I've checked through the way the different (one working & one not) controls are set up and even back to the queries and tables they come from. While there are some minor differences, I can't see anything which points to why.
I was able to sort out this problem. I just marked that line (#5 in your posting, #9 in this posting) a comment instead. It seems that took care of the problem. Let me know if this is not the right way to fixing this issue. Here are the revised codes and it's working now. Lots of thanks for your help.

Expand|Select|Wrap|Line Numbers
  1. Private Sub SongTitleID_DblClick(Cancel As Integer)
  2. On Error GoTo Err_SongTitleID_DblClick
  3.     Dim lngSongID As Long
  4.  
  5.     If IsNull(Me![SongTitleID]) Then
  6.         Me![SongTitleID].Text = ""
  7.     Else
  8.         lngSongTitleID = Me![SongTitleID]
  9.         'Me![SongTitleID] = Null
  10.     End If
  11.     DoCmd.OpenForm "frmSongs", , , , , acDialog, "GotoNew"
  12.     Me![SongTitleID].Requery
  13.     If lngSongTitleID <> 0 Then Me![SongTitleID] = lngSongTitleID
  14.  
  15. Exit_SongTitleID_DblClick:
  16.     Exit Sub
  17.  
  18. Err_SongTitleID_DblClick:
  19.     MsgBox Err.Description
  20.     Resume Exit_SongTitleID_DblClick
  21. End Sub
Oct 17 '08 #148
NeoPa
32,556 Expert Mod 16PB
I tried that first. Unfortunately it doesn't really solve the problem. It works sometimes, but not in other circumstances :(

I would say it's a worthwhile compromise for the moment though. It's better than not working at all :)
Oct 17 '08 #149
NeoPa
32,556 Expert Mod 16PB
Please check your PMs and let me know your response.
Did you manage to check your PMs yet?
Oct 17 '08 #150

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

Similar topics

8
by: Asad | last post by:
Hi, I am basically trying to accomplish drop down menus for navigation on a site. And I'm pretty much done except I am having one problem. The z-index is not working with relative positioning! ...
8
by: Andr? Queiroz | last post by:
Hi, I have a table with 10M records and col A has a index created on it. The data on that table has the same value for col A on all 10M records. After that I insert diferent values for that column...
14
by: Sean C. | last post by:
Helpful folks, Most of my previous experience with DB2 was on s390 mainframe systems and the optimizer on this platform always seemed very predictable and consistent. Since moving to a WinNT/UDB...
0
by: Graham | last post by:
Hi everyone I have a form which contains a ListView control. The code handles the SelectedIndexChanged event, and changes some icons on some items in the ListView. I've found that when I...
14
by: Rich | last post by:
Yes, I need to store some values in an array type collection object that can hold 3 or more parameters per index. I have looked at the collection object, hashtable object and would prefer not to...
2
by: Martin v. Löwis | last post by:
I've been working on PEP 353 for some time now. Please comment, in particular if you are using 64-bit systems. Regards, Martin PEP: 353 Title: Using ssize_t as the index type Version:...
8
by: Joe Rattz | last post by:
Ok, I can't believe what I am seeing. I am sure I do this other places with no problems, but I sure can't here. I have some code that is indexing into the ItemArray in a DataSet's DataRow. I...
5
by: lightgram | last post by:
Hi I have a problem, which after browsing through Google, seems to be fairly common. However having tried most suggestions I am still getting the problem. I have a menu bar across the top...
1
by: sksksk | last post by:
I want to achieve the following process in the smarty for $item one i should be able to get the value using loop.index, but without any luck. any help is appreciated. <?php for ($i = 1; $i...
3
by: Christof Warlich | last post by:
Hi all, in the following example, Index<unsigned int x>::value allows to calculate the "rounded up" index from any "increasing" value during compile time. Unfortunately, the definition of the...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
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.