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

Run-time Errorless Bookmark/DLookUp Module Not Working

34
In my .accdb, DAO Db, I'm trying to use an AfterUpdate or OnLostFocus event procedure in a class module to populate a date on two tables. My form control is
bound to the "MovieCodeSendDate" field on my master table, and I want the field of the same name on my detail table to be populated by the event procedure. I
have the following code in place which neither produced errors nor works. It first bookmarks the relevant form control and detail table field by looking up a pivot value ("MovieCode") in a listbox, then (attempts to) populate it with a DLookUp statement. I'm not sure if there's a problem in the environment, my references, or what. Like I said, the code doesn't error in run-time, yet doesn't work when I check the table for the date that's supposed to populate next to the correct movie code.

- My form is based on a query that includes every field from both tables (".*").
- The "MovieCode" field for both tables is the primary key.
- I took out the join on "MovieCode" between them because the relationship between them will always be one to one and I think the join was messing up my Form control source query statement in relation to this procedure.

Expand|Select|Wrap|Line Numbers
  1. Private Sub A1_Tracking_Form_Movie_Code_Send_Date_Control_On_Lost_Focus()
  2.  
  3.  
  4. ' When the "Movie Code Send Date" control text box is tabbed off of, this code will find the same code in the Movie Code Table that is
  5. ' populated in the listbox of the current record... 
  6.  
  7. ' First, the fields that have already been data-entered are saved for good measure.
  8.  
  9. DoCmd.RunCommand acCmdSaveRecord
  10.  
  11.  
  12. On Error GoTo PROC1_ERR
  13.  
  14. Dim rs as DAO.Recordset
  15.  
  16. Set rs = Me.RecordsetClone
  17.  
  18. rs.FindFirst "[A1 Movie Code Table].[MovieCode]= '" & Me.[A1 Tracking Form Movie Code List Box] & "'"
  19.  
  20. Forms![A1 Onboarding Tracking Form].Bookmark = rs.Bookmark
  21.  
  22. If rs.NoMatch Then
  23.    Msgbox "No match found.", vbInformation + vbOKOnly
  24. Else
  25.   Me.Bookmark = rs.Bookmark
  26. End If
  27.  
  28. Debug.Print ("Find matching movie code between form control and movie code table")
  29.  
  30. PROC1_EXIT:
  31. Exit Sub
  32.  
  33. PROC1_ERR:
  34. MsgBox "Error finding matching movie code between form control and movie code table." & _
  35. vbCrLf & "Check in table to see if code you picked is already used." & vbCrLf & Err.Number & " " & _
  36. Err.Description, vbExclamation + vbOKOnly, "Find Matching Control Code In Movie Code Table"
  37.  
  38. Resume PROC1_EXIT
  39.  
  40. rs.Close
  41.  
  42.  
  43. ' If found, code will next populate the movie code send date cell right next to
  44. ' the correct code. This will ensure only new codes are available in the movie code listbox during
  45. ' data entry and prevent the sending of one code to more than one employee.
  46.  
  47. On Error GoTo PROC2_ERR
  48.  
  49. Dim dt As Date
  50.  
  51. dt = DLookup("[MovieCodeSendDate]", "[A1 Movie Code Table]", "[MovieCode] =" & Forms![A1 Onboarding Tracking Form]!MovieCodeSendDate)
  52.  
  53. Debug.Print ("Populate moviecodesenddate from form control to movie code table")
  54.  
  55. PROC2_EXIT:
  56. Exit Sub
  57.  
  58. PROC2_ERR:
  59. MsgBox "Error populating moviecodesenddate from from control to movie code table." & _
  60. vbCrLf & "Check in table to see if code you picked is already used." & vbCrLf & Err.Number & " " & _
  61. Err.Description, vbExclamation + vbOKOnly, "Populate Form Send Date In Movie Code Table"
  62.  
  63. Resume PROC2_EXIT
  64.  
  65. End Sub
I can't for the life of me figure out what is going on. No results, no run-time errors. To my understanding the bookmark procedure only marks the cells to share values, and the DLookup procedure actually populates the receiving cell. Any ideas about what is going wrong here are greatly appreciated. Thank you.

Frank
Feb 3 '12 #1
9 1902
ADezii
8,834 Expert 8TB
I did not read the Post in depth for now, but only glanced at the Code, so forgive me if I am wrong.
  1. Make sure that the Recordset supports Bookmarks, namely:
    Expand|Select|Wrap|Line Numbers
    1. MsgBox IIf(rs.Bookmarkable, "Supports", "Does NOT Support") & " Bookmarks"
  2. In Line# 20, you are assigning the Bookmark Property of Form [A1 Onboarding Tracking Form] to the results of the FindFirst() Method, without knowing whether or not a Match was returned.
  3. Bookmark may not be transferable to the Form mentioned above.
Feb 3 '12 #2
soule
34
Hello, ADezii. Thank you so much for replying to my problem. This task has given me 3 weeks worth of grief. Here's where I am now:

1. I don't understand about Bookmarks being supported. Isn't that a DAO library consideration? Why would my code have to verify this every time it ran? Could you please explain?

2. Do you think this arrangement would work instead?

Expand|Select|Wrap|Line Numbers
  1. Dim rs as DAO.Recordset 
  2.  
  3. Set rs = Me.RecordsetClone 
  4.  
  5. rs.FindFirst "[A1 Movie Code Table].[MovieCode]= '" & Me.[A1 Tracking Form Movie Code List Box] & "'" 
  6.  
  7. If rs.NoMatch Then 
  8.    Msgbox "No match found.", vbInformation + vbOKOnly 
  9. Else 
  10.   Me.Bookmark = rs.Bookmark 
  11. End If
  12.  
  13. Forms![A1 Onboarding Tracking Form].Bookmark = rs.Bookmark
  14.  
  15. Debug.Print ("Find matching movie code between form control and movie code table")
3. I have my fingers crossed. More research! :S
Feb 4 '12 #3
ADezii
8,834 Expert 8TB
Change the Syntax, and let's see if the 2 Bookmarks are exactly the same:
Expand|Select|Wrap|Line Numbers
  1. Dim rs As DAO.Recordset
  2.  
  3. Set rs = Me.RecordsetClone
  4.  
  5. rs.FindFirst "[MovieCode]= '" & Me.[A1 Tracking Form Movie Code List Box] & "'"
  6.  
  7. If rs.NoMatch Then
  8.    MsgBox "No match found.", vbInformation + vbOKOnly
  9. Else
  10.   Me.Bookmark = rs.Bookmark
  11.     MsgBox IIf(StrComp(Me.Bookmark, rs.Bookmark, vbBinaryCompare) = 0, "Exact Match", "Bookmarks Different")
  12. End If
Feb 4 '12 #4
soule
34
Hi, ADezii,

Thanks for taking more time to look at my problem. I inserted the IIf statement in my If..EndIf statement and it worked great. I got an "exact match" message box. Here is my current version of my code. I moved the code from the form class mod to a standard mod in order to be able to compile it. I moved down my "Dim dt As Date" statement to the second procedure so it was closer to the code that uses it. I also used my "dt" term twice in the second procedure. I'm still not getting any compile nor run-time errors, but no results either. Should I move my "Dim rs" after my DoCmd save record command? Anything you can see that I'm missing?

Expand|Select|Wrap|Line Numbers
  1. Option Compare Database
  2. Option Explicit
  3.  
  4. Private Sub A1_Tracking_Form_Movie_Code_Send_Date_Control_LostFocus()
  5.  
  6. ' When the "Movie Code Send Date" control text box is tabbed off of, this code will find the same code in the Movie Code Table that
  7. ' is populated in the listbox of the current record...
  8.  
  9. ' First, the fields that have already been data-entered are saved for good measure.
  10.  
  11. Dim rs As DAO.Recordset
  12.  
  13.   DoCmd.RunCommand acCmdSaveRecord
  14.  
  15. On Error GoTo PROC1_ERR
  16.  
  17.   Set rs = Forms![A1 Onboarding Tracking Form].RecordsetClone
  18.  
  19.   rs.FindFirst "[A1 Movie Code Table].[RawMovieCode]= '" & Forms![A1 Onboarding Tracking Form].[A1S1 Tracking Form Movie Code List Box] & "'"
  20.  
  21.   Forms![A1 Onboarding Tracking Form].Bookmark = rs.Bookmark
  22.  
  23.   If rs.NoMatch Then
  24.     MsgBox "No match found.", vbInformation + vbOKOnly
  25.   Else
  26.     Forms![A1 Onboarding Tracking Form].Bookmark = rs.Bookmark
  27.   End If
  28.  
  29.   Debug.Print ("Find matching movie code between form control and movie code table")
  30.  
  31.   rs.Close
  32.  
  33. ' If found, code will next populate the movie code send date cell right next to
  34. ' the correct code. This will ensure only new codes are available in the movie code listbox during
  35. ' data entry and prevent the sending of one code to more than one employee.
  36.  
  37. On Error GoTo PROC2_ERR
  38.  
  39.   Dim dt As Date
  40.  
  41.   dt = DLookup("[MovieCodeSendDateClone]", "[A1 Movie Code Table]")
  42.   dt = Forms![A1 Onboarding Tracking Form]!MovieCodeSendDate
  43.  
  44.   Debug.Print ("Populate moviecodesenddate from form control to movie code table")
  45.  
  46. PROC_EXIT:
  47.   Exit Sub
  48.  
  49. PROC1_ERR:
  50.   MsgBox "Error finding matching movie code between form control and movie code table." & _
  51.     vbCrLf & "Check in table to see if code you picked is already used." & vbCrLf & Err.Number & " " & _
  52.     Err.Description, vbExclamation + vbOKOnly, "Find Matching Control Code In Movie Code Table"
  53.   Resume PROC_EXIT
  54.  
  55. PROC2_ERR:
  56.   MsgBox "Error populating moviecodesenddate from from control to movie code table." & _
  57.     vbCrLf & "Check in table to see if code you picked is already used." & vbCrLf & Err.Number & " " & _
  58.     Err.Description, vbExclamation + vbOKOnly, "Populate Form Send Date In Movie Code Table"
  59.   Resume PROC_EXIT
  60.  
  61. End Sub
Thank you for your previous help. Anything about this version will be appreciated too.

Frank
Feb 11 '12 #5
ADezii
8,834 Expert 8TB
I still think that the problem lies in the fact that you cannot simply assign a Bookmark in the manner which you have described. Try modifying the Form's Recordset or Record Source properties based on the Bookmarked Record Values.
Feb 11 '12 #6
Stewart Ross
2,545 Expert Mod 2GB
You are setting a local VBA variable called dt (line 41) and overwriting it immediately (line 42). You are not populating any field at all with its value. Variable dt has no existence outside of the sub concerned - its value cannot persist unless you assign it to a bound control on a form, or directly via SQL to a field in a table.

In the original post you made you were not assigning the value of dt to anything at all either (line 51 in post #1), so this is an error in your approach all along.

The second assignment at line 42 in post # 6 above should surely be reversed if you want to set the value of the moviecodesenddate field:

Expand|Select|Wrap|Line Numbers
  1. Forms![A1 Onboarding Tracking Form]!MovieCodeSendDate = dt
I'm not convinced that you understand the logic of what you are trying to do. In the first post you appeared to believe your Dlookup would populate MovieCodeSendDate - but it was just rather circularly looking up the value from a where clause that itself referred to MovieCodeSendDate from the same table. In your last post your Dlookup is loooking up a field called MovieCodeSendDateClone, whatever that is, which may or may not be what you want to achieve - I can't say it is clear that the lookup value is the one you want at all, or that this has any relation at all to the bookmarking of the cloned recordset.

Perhaps if you told us what the lookup and bookmarking was trying to achieve we could assist with clearing up the logic concerned.

-Stewart
Feb 11 '12 #7
soule
34
Hello, Stewart,

Thank you very much for taking a look at my LostFocus code. I really appreciate it.

Though I know it isn't good Db design, I need to store a value in two tables. I need to so I can update the "used or unused" status of alphanumeric movie codes that will be added to that table and that feed a queried listbox on my form. I have a master table and a detail table. When a user enters a "movie code send date" on the form, it populates the field on the master table it's bound to, but I also need it to do the same on the correct movie code line on LostFocus in the detail table. I'm intending the bookmarking to recognize matching movie codes on the form and in the detail table by value, and then populate the corresponding "moviecodesenddate" field of that match with the send date entered on the form when that date control loses focus. Because people don't store data in two places (a wise practice), no one seems to know how to do this.

I'll take another look at my dimensioning like you recommended and make sure the logic is sound...thanks.
Feb 14 '12 #8
Stewart Ross
2,545 Expert Mod 2GB
I should also mention, as ADezii has already done, that bookmarking is not necessarily the right approach. You can only apply bookmarks to and from recordsets which are identical - as is the case when recordsetclone is used to clone the current form's recordset, a find is performed, a match found, and the form set to the clone bookmark to move it to the right position.

Bookmarks will not assign correctly or give meaningful results from one recordset to another if the underlying recordsets are not identical.

In any case, from what you have shown us so far I think if you clarify the logic you are applying it will be possible to do what you require either by joining suitable tables together for a special-purpose query, or by using the existing DLookup or similar domain functions WITHOUT trying to sync a form first.

It all depends on knowing the steps you wish to take.

Relational databases are designed to avoid data redundancy in most situations; keeping copies of specific field values in separate places is not normal practice, unless there are very good reasons to do so.

-Stewart
Feb 14 '12 #9
soule
34
Thanks for replying again, Stewart.

I'm in a professional situation where I don't have the time or resources to learn the finer points of VB and it's making this project extremely difficult...I'm having to learn VB while I'm creating a Db with e-mail automation buttons and a table structure that demands two fields of redundant data. Thanks for the advice about bookmarking and your time.

To my understanding, my "DoCmd.RunCommand acCmdSaveRecord" command will ensure the form recordset and its clone are identical by updating any data-entered controls into the recordset before cloning. Am I missing something?

I tried a DLookup function method before adding bookmarking, but couldn't get it to work. It wouldn't work because I need to attach a date in a date field of a specific record in my detail table, and just couldn't make it happen after 2+ weeks of research and trying. I don't know if anyone knows how to make a seemingly simple event code happen. I'm so fried I don't even remember the error.

The degree to which I'd appreciate any more advice (preferably in the form of code) you'll never know.

Frank
Feb 14 '12 #10

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

Similar topics

3
by: leroybt.rm | last post by:
Can someone tell me how to run a script from a interactive shell I type the following: >>>python filename >>>python filename.py >>>run filename >>>run filename.py >>>/run filename >>>/run...
8
by: Jonathan Polley | last post by:
I have one account on a WindowsXP machine that refuses to run IDLE (or any other python script that uses Tk). Other people can login to that PC and IDLE runs just fine, so it is not an...
4
by: Ed | last post by:
Hello, I took a course in asp about 2 years ago and I was practicing with IIS 5.0. Then I put it down for a while. Now trying to get back to it. I can't run asp files from subdirectories of...
5
by: Patrice FRITSCH | last post by:
I'm trying to run a batch file from an asp page using WScript.Shell object. Dim oWSH set oWSH= Server.CreateObject("WScript.Shell") call oWSH.Run("cmd.exe /c " & szCmd , 0, true) szCmd...
2
by: Jenna Olson | last post by:
Hi all- I've never seen this particular issue addressed, but was wondering if there's anything to support one way or another. Say I have a class: class ManipulateData { public:...
15
by: mg | last post by:
How can I run an .exe using C# from within the code behind of a WebForm app?
4
by: Primo | last post by:
Hi, This problem has been frustrating me for days and I hope you experts can help me out. I am trying to run a command, which I would normally run from the command line, from within my C#...
6
by: orekin | last post by:
Hi There I have been trying to come to grips with Application.Run(), Application.Exit() and the Message Pump and I would really appreciate some feedback on the following questions .. There are...
6
by: billr | last post by:
I have developed a small API for taking care of a lot of boiler plate stuff in a multi formed windows application, for example setting up a messaging thread framework. New Forms, in the...
13
by: Bob Day | last post by:
Using vs2003, vb.net I start a thread, giving it a name before start. Code snippet: 'give each thread a unique name (for later identification) Trunk_Thread.Name = "Trunk_0_Thread" ' allow...
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:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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
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?
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,...

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.