By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,501 Members | 2,768 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,501 IT Pros & Developers. It's quick & easy.

Problem Moving To Next Record

MindBender77
100+
P: 234
Hello All,
I believe I have a simple problem but, can't seem to find a easy solution. First, I developed a form (popup) with 2 combo boxes and a submit button.

When I make a choice from both cbo and click submit, a form corresponding to the entries are displayed. However, when the form tries to open, I get an error stating "Can Not Go To Specified Record in Design View."

I'm using the this code to open the form.
Expand|Select|Wrap|Line Numbers
  1. DoCmd.OpenForm "FormName", acNormal
  2.  
Any Help Will Be Appreciated,
Bender

PS - If I open the form directly, I do not get the error.
Apr 11 '08 #1
Share this Question
Share on Google+
9 Replies


missinglinq
Expert 2.5K+
P: 3,532
When I make a choice from both cbo and click submit, a form corresponding to the entries are displayed.
Are you, in fact, asking Access to go to a particular record when the form opens, and if so, how?

There's obviously nothing wrong with the code you've posted, but neither does it demonstrate how the values selected from your comboboxes are being assigned to this process, and we need to see that code.

Linq ;0)>
Apr 11 '08 #2

MindBender77
100+
P: 234
Basically the code for the Submit button which opens the form is:
X and Y are String data types
Expand|Select|Wrap|Line Numbers
  1. if ComboBox1 = X and cbo2 = Y then
  2. docmd.openform "formname", acNormal
  3. end if
  4.  
Then here is the code that is produces the error. Note, it works as it should when opening the form directly, without the comboboxes.
Expand|Select|Wrap|Line Numbers
  1. Dim date_cleaned, Cell
  2. Dim cleanings
  3. Dim PDate As Date
  4.  
  5.     PDate = DateValue(Format(Now, "mm/dd/yyyy"))
  6.     Cell = txt_cell
  7.  
  8.  
  9.     Call last_cleaned 'Runs An Append Query.  Appending Last Cleaned Date and count of cleanings to table "tbl_Last_Date_Cleaned_91-1"
  10.  
  11.     cleanings = DLookup("[Number of Cleanings]", "tbl_Last_Date_Cleaned_91-1")
  12.     date_cleaned = DLookup("[LastOfDate]", "tbl_Last_Date_Cleaned_91-1")
  13.  
  14.     If txt_frequency = "Twice a Shift" And cleanings <= 1 And date_cleaned <= PDate Then
  15.         DoCmd.OpenQuery ("qry_Delete_Last_Date_Cleaned_91-1")
  16.         Exit Sub
  17.     Else
  18.         DoCmd.GoToRecord , , acNext 'This Is Where The Error Occurs
  19.         DoCmd.OpenQuery ("qry_Delete_Last_Date_Cleaned_91-1")
  20.     End If
  21.  
Bender
Apr 11 '08 #3

NeoPa
Expert Mod 15k+
P: 31,494
Frustratingly, probably the most important piece of information is what you left out :D

Where is the second batch of code to be found and what is the procedure called (I suspect it may be the Form_Open() procedure in the form's own module)?
Apr 11 '08 #4

MindBender77
100+
P: 234
I didn't think the OnOpen was causing the issue but, then again, I'm the one stumped on this so any help would be tremendous:

Bender

Expand|Select|Wrap|Line Numbers
  1. Private Sub Form_Open(Cancel As Integer)
  2. Dim current_day
  3.  
  4.  
  5. DoCmd.RunMacro ("Minimize") 'Minimizes the Access window allowing just the form to be visible
  6. current_day = Format(Weekday(Now, vbSunday), "dddd")
  7.  
  8.  
  9. If current_day = "Sunday" Then
  10. ck_sunday.Enabled = True
  11. ck_monday.Enabled = False
  12. ck_tuesday.Enabled = False
  13. ck_wednesday.Enabled = False
  14. ck_thursday.Enabled = False
  15. ck_friday.Enabled = False
  16. ck_sunday = 0
  17.  
  18.  
  19. ElseIf current_day = "Monday" Then
  20. ck_sunday.Enabled = False
  21. ck_monday.Enabled = True
  22. ck_tuesday.Enabled = False
  23. ck_wednesday.Enabled = False
  24. ck_thursday.Enabled = False
  25. ck_friday.Enabled = False
  26. ck_monday = 0
  27.  
  28.  
  29. ElseIf current_day = "Tuesday" Then
  30. ck_sunday.Enabled = False
  31. ck_monday.Enabled = False
  32. ck_tuesday.Enabled = True
  33. ck_wednesday.Enabled = False
  34. ck_thursday.Enabled = False
  35. ck_friday.Enabled = False
  36. ck_tuesday = 0
  37.  
  38. ElseIf current_day = "Wednesday" Then
  39. ck_sunday.Enabled = False
  40. ck_monday.Enabled = False
  41. ck_tuesday.Enabled = False
  42. ck_wednesday.Enabled = True
  43. ck_thursday.Enabled = False
  44. ck_friday.Enabled = False
  45. ck_wednesday = 0
  46.  
  47. ElseIf current_day = "Thursday" Then
  48. ck_sunday.Enabled = False
  49. ck_monday.Enabled = False
  50. ck_tuesday.Enabled = False
  51. ck_wednesday.Enabled = False
  52. ck_thursday.Enabled = True
  53. ck_friday.Enabled = False
  54. ck_thursday = 0
  55.  
  56. ElseIf current_day = "Friday" Then
  57. ck_sunday.Enabled = False
  58. ck_monday.Enabled = False
  59. ck_tuesday.Enabled = False
  60. ck_wednesday.Enabled = False
  61. ck_thursday.Enabled = False
  62. ck_friday.Enabled = True
  63. ck_friday = 0
  64.  
  65. ElseIf current_day = "Saturday" Then
  66. ck_sunday.Enabled = False
  67. ck_monday.Enabled = False
  68. ck_tuesday.Enabled = False
  69. ck_wednesday.Enabled = False
  70. ck_friday.Enabled = False
  71. ck_saturday.Enabled = True
  72. ck_saturday = 0
  73. End If
  74.  
  75. End Sub
  76.  
Apr 14 '08 #5

NeoPa
Expert Mod 15k+
P: 31,494
Bender, I suspect, in effect, it's not (though I have provided an alternative that's a little shorter).

What I was asking for (sorry I didn't make this clearer) was the information that showed how the second block of code in your post (#3) fitted into the situation (how is it executed).

What you provided was fine, but I couldn't see what I needed in it so I asked for some extra info. Clearly you were careful not to overload the post with useless info which I can only applaud, but sometimes useful bits are missed out too. It's a call you have to make, and I far prefer posters who make that call and maybe get it a little wrong to those who don't even get the concept.
Expand|Select|Wrap|Line Numbers
  1. Private Sub Form_Open(Cancel As Integer)
  2.   Dim Current_Day As String
  3.   Dim ctlMe As Control
  4.  
  5.   DoCmd.RunMacro ("Minimize") 'Minimizes the Access window allowing just the form to be visible
  6.   Current_Day = Format(Date(), "dddd")
  7.  
  8.   ck_Sunday.Enabled = False
  9.   ck_Monday.Enabled = False
  10.   ck_Tuesday.Enabled = False
  11.   ck_Wednesday.Enabled = False
  12.   ck_Thursday.Enabled = False
  13.   ck_Friday.Enabled = False
  14.   ck_Saturday.Enabled = False
  15.  
  16.   For Each ctlMe In Me.Controls
  17.     If Mid(ctlMe.Name, 4) = Current_Day Then
  18.       ctlMe.Enabled = True
  19.       ctlMe = 0
  20.     End If
  21.   Next ctlMe
  22.  
  23. End Sub
In your code ck_Saturday was omitted from most groups (and ck_Thursday was omitted for the Saturday group). I assumed this was an oversight and coded accordingly.
Apr 14 '08 #6

MindBender77
100+
P: 234
I am uncertain on the usage of "For Each" and I seem to stay away from it. As you illustrated, I definitely have to build up my confidence in its functions.

As for the code I left out: At the end of the OnOpen event, there is a call to a sub. Here is its code. Note: The call frequency_check_daily is from Post #3.
Expand|Select|Wrap|Line Numbers
  1. Private Sub Aggitator()
  2. Dim msg, style, title, response
  3. Dim Unit, Cell
  4.  
  5. Unit = txt_unit
  6. Cell = txt_cell
  7.  
  8. If txt_frequency = "" Or IsNull(txt_frequency) = True Or IsNull(Cell) = True Then
  9. msg = "There Is Currently No Cell That Needs Maintenance At This Time."
  10. style = vbOKOnly + vbInformation + defaultbutton2
  11. title = "Plus Bank Maintenance"
  12. response = MsgBox(msg, style, title)
  13. ck_sunday.Enabled = False
  14. ck_monday.Enabled = False
  15. ck_tuesday.Enabled = False
  16. ck_wednesday.Enabled = False
  17. ck_thursday.Enabled = False
  18. ck_friday.Enabled = False
  19. Else
  20.  
  21. If txt_frequency = "Twice a Shift" Then
  22. Call frequency_check_shift 'Each of these is basically the same as (Post #3)
  23. End If
  24.  
  25. If txt_frequency = "Daily" Then
  26. Call frequency_check_daily
  27. End If
  28.  
  29. If txt_frequency = "Weekly" Then
  30. Call frequency_check_weekly
  31. End If
  32.  
  33. If txt_frequency = "Monthly" Then
  34. Call frequency_check_monthly
  35. End If
  36.  
  37.  
  38. End If
  39.  
  40. End Sub
  41.  
Apr 14 '08 #7

NeoPa
Expert Mod 15k+
P: 31,494
I'm sorry, but it's still unclear where the code (the stuff with the error in) is being run from.

This is particularly important as the line where the error occurs is unspecific code. It works on the current object (not on the form that's yet to be opened) so without knowing where we are at the time of execution I can see no way to determine what's going wrong.
Apr 15 '08 #8

MindBender77
100+
P: 234
I'm sorry for being unclear,Neopa. I do appreciate all your help. I'm going to attempt to find the solution through alittle trial and error since I'm between projects. I don't want to fill this thread with useless code snippits and waste yours and others time when it could be used helping others. I'll post the solution when it is found.

Thanks Again,
Bender
Apr 15 '08 #9

NeoPa
Expert Mod 15k+
P: 31,494
...
Expand|Select|Wrap|Line Numbers
  1. DoCmd.GoToRecord , , acNext 'This Is Where The Error Occurs
...
OK No worries.

If I can just share my thoughts so far, they may be of some help.

I'm guessing (can't be sure) that this line is intended to operate within a form (possibly the one that has yet to be called) but is actually operating elsewhere. This is a side-effect of the API provided to be very general purpose (DoCmd...). If possible (it isn't in all cases unfortunately) re-code this to refer to an object explicitly. This has a side-effect of being more obvious when read too (so is better coding practice generally).

Good luck with your attempts and let us know how you get on :)
Apr 15 '08 #10

Post your reply

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