473,472 Members | 1,761 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Subform requery problem

12 New Member
Hi guys,
I recently rewrote onClick procedure for Calendar on my form (frmRota). It opens record from tblRotas where field rDate is equal the one selected on Calendar. If such a record doesnt exist I want it to be created. Before only way to create new record was to click on NewRecord button that I created using Access2003 button wizard. Calendar is not bound to any field in recordsource but on this form I have text box rDate that is bound to tblRota.rDate field which I update at the end of onClick procedure. Everything is ok when record exists - but when I try to create new record by clicking on Date that doesnt have corresponding record in my table (tblRotas) I get an error when populating combobox on subform attached to the frmRota form. Error is : "You entered an expression that has an invalid reference to the property Form/Report."
I distinguished the line that produces the error.
I know that my explanation might be a bit confusing I am pretty much novice in Access DB programming so please excuse me not the best vb code. Here is all the code attached to frmRota:

Expand|Select|Wrap|Line Numbers
  1.  Private Sub Calendar1_Click() 
  2. GBL_CurrRotaDate = Me.Calendar1
  3. GBL_CurrRotaDay = Get_DayFromDate(CStr(GBL_CurrRotaDate))
  4. Me.rWeekNo = Format(GBL_CurrRotaDate, "ww") - 8
  5. If Me.rWeekNo <= 0 Then
  6. Me.rWeekNo = Me.rWeekNo + 55
  7. End If
  8. STRSQL = "Select count(rDate) as Rcount from tblRotas where rDate = CDATE('" & GBL_CurrRotaDate & "')"
  9. Set Db = CurrentDb
  10. Set rs = Db.OpenRecordset(STRSQL)
  11. If Not rs.EOF Then
  12.  
  13. 'Check if Rota for that date already exists
  14. If rs!Rcount >= 1 Then ' Rota already exists
  15.  
  16. Me.rDate.SetFocus
  17. DoCmd.FindRecord Me.Calendar1, acEntire
  18. rs.Close
  19. Db.Close
  20. Exit Sub
  21. Else 'rota doesnt exist so create new record
  22. rs.Close
  23. Db.Close
  24. Me.Form.SetFocus
  25. DoCmd.GoToRecord , , acNewRec 
  26. If Not Me.Calendar1 Then 
  27. Me.rDate = Me.Calendar1 'calendar not bound to tblRotas.rDate so need to update rDate box which is bound to rDate field in tblRotas table
  28. GBL_CurrRotaDate = Me.Calendar1 'setting global rota date
  29. GBL_CurrRotaDay = Get_DayFromDate(CStr(GBL_CurrRotaDate))
  30. Me.rDate = Me.Calendar1
  31. Me.rWeekNo = Format(GBL_CurrRotaDate, "ww") - 8 ' where I leave financial year starts from March thats why -8 
  32. If Me.rWeekNo <= 0 Then 'if current data between January and March update week by adding 55 so week is not negative
  33. Me.rWeekNo = Me.rWeekNo + 55
  34. End If
  35. End If
  36. PopulateListsBoxes 'function at the end of frmRota module - within which I receive error when creating new record
  37.  
  38. End If
  39. End If
  40.  
  41. End Sub
  42.  
Expand|Select|Wrap|Line Numbers
  1.  Private Sub Form_Current() 
  2. Dim rs As Recordset
  3. Dim Db As Database
  4. Dim STRSQL As String
  5.  
  6. If Not Me.rDate Then
  7. Me.Calendar1 = Me.rDate
  8. End If
  9.  
  10. If Not Me.CurrentRecord Then
  11. Me.Caption = "Create Rota No. " & Me.CurrentRecord
  12. End If
  13. If Not Len(Me.rDate) = 0 Then
  14. GBL_CurrRotaDate = Me.rDate
  15. GBL_CurrRotaDay = Get_DayFromDate(CStr(GBL_CurrRotaDate))
  16. PopulateListsBoxes
  17. End If
  18. End Sub
  19.  
Expand|Select|Wrap|Line Numbers
  1.  Private Sub sfrmRota_Enter() 
  2. If Me.rDate = 0 Then 'rDate is what bounds frmRota with sfrmRota so it cant be NULL or 0
  3. MsgBox "Please Select Date First"
  4. Me.Calendar1.SetFocus
  5. End If
  6. If IsNull(Me.rDate) Then 'rDate is what bounds frmRota with sfrmRota so it cant be NULL or 0
  7. MsgBox "Please Select Date First"
  8. Me.Calendar1.SetFocus
  9. Exit Sub
  10. End If
  11. End Sub
  12.  
Expand|Select|Wrap|Line Numbers
  1.  Public Function PopulateListsBoxes() 
  2. Set Db = CurrentDb
  3. CurrentDb.Execute ("Delete from tblAvailableEmployees")
  4. STRSQL = "Insert into tblAvailableEmployees (EmployeeID) Select employeeID from tblDaysOff where " & GBL_CurrRotaDay & _
  5. "=0" 'Selecting employees that are contracted on selected day
  6. CurrentDb.Execute (STRSQL)
  7. STRSQL = "Insert into tblAvailableEmployees (EmployeeID) Select employeeID from tblOT where otDate = #" & GBL_CurrRotaDate & "#;" 'Adding employees that agreed to do Overtime 
  8. CurrentDb.Execute (STRSQL)
  9. Me.sfrmRota.Controls.Item(2).Requery 'Thats the part that errors when creating new record. I am using this for combobox( item(2) on subform ) to requery tblAvailableEmployees for new data
  10.  
  11. End Function
  12.  
Dec 1 '07 #1
10 2209
puppydogbuddy
1,923 Recognized Expert Top Contributor
try this syntax:

Me!sfrmRota.Form!Item(2).Requery
Dec 1 '07 #2
AdrianGawrys
12 New Member
try this syntax:

Me!sfrmRota.Form!Item(2).Requery
Thanks but unfortuantely this doesn't help.
Dec 2 '07 #3
puppydogbuddy
1,923 Recognized Expert Top Contributor
Thanks but unfortuantely this doesn't help.
Please provide some details.......I am not sitting at your computer....what happens.....what is the error message ?
Dec 2 '07 #4
AdrianGawrys
12 New Member
Please provide some details.......I am not sitting at your computer....what happens.....what is the error message ?
Like I wrote in my first post - Error message is
"You entered an expression that has an invalid reference to the property Form/Report." and it comes up under line 9 of PopulateListsBoxes() function but only when condition from line 14 (If rs!Rcount >= 1 Then) of "Private Sub Calendar1_Click()" is False - meaning: there is no rota in tblRotas with date (rDate) specified by user (value of Calendar1) if condition from line 14 is met then PopulateListsBoxes doesn't fail - no error whatsoever.
Any ideas? I can't find a workaround to this problem.
Dec 5 '07 #5
puppydogbuddy
1,923 Recognized Expert Top Contributor
Like I wrote in my first post - Error message is
"You entered an expression that has an invalid reference to the property Form/Report." and it comes up under line 9 of PopulateListsBoxes() function but only when condition from line 14 (If rs!Rcount >= 1 Then) of "Private Sub Calendar1_Click()" is False - meaning: there is no rota in tblRotas with date (rDate) specified by user (value of Calendar1) if condition from line 14 is met then PopulateListsBoxes doesn't fail - no error whatsoever.
Any ideas? I can't find a workaround to this problem.

Well, if you want to fire the code below when you have an existing record:
=================================================
Me.sfrmRota.Controls.Item(2).Requery 'Thats the part that errors when creating new record. I am using this for combobox( item(2) on subform ) to requery tblAvailableEmployees for new data

Why can't you do it like this:
========================
If Not Me.NewRecord then
Me.sfrmRota.Controls.Item(2).Requery
Else
' what you want program to do if you have a new record
End If
Dec 5 '07 #6
AdrianGawrys
12 New Member
Well, if you want to fire the code below when you have an existing record:
=================================================
Me.sfrmRota.Controls.Item(2).Requery 'Thats the part that errors when creating new record. I am using this for combobox( item(2) on subform ) to requery tblAvailableEmployees for new data

Why can't you do it like this:
========================
If Not Me.NewRecord then
Me.sfrmRota.Controls.Item(2).Requery
Else
' what you want program to do if you have a new record
End If
Thanks a bunch, I feel like I am slowly moving in a good direction but the problem is that Me.NewRecord is set to 0 at this point for some reason. @puppydogbuddy would you be interested in looking into the database file itself? I can share them somewhere on public location and send you link if you are interested.
Dec 6 '07 #7
puppydogbuddy
1,923 Recognized Expert Top Contributor
Thanks a bunch, I feel like I am slowly moving in a good direction but the problem is that Me.NewRecord is set to 0 at this point for some reason. @puppydogbuddy would you be interested in looking into the database file itself? I can share them somewhere on public location and send you link if you are interested.
Adrian,
The code I gave you was : If <<<Not>>> Me.NewRecord then.

If you need me to look at the file, you can zip and email to the address on my VCard (with my profile), In order for me to look at your file, it has to be Access version 2000 or 1997(can convert to 2000).
Dec 6 '07 #8
puppydogbuddy
1,923 Recognized Expert Top Contributor
Adrian,
Just noticed this. Could line 7 be your problem? it looks to me like line 7 is backwards. I think it should be: Me.rDate = Me.Calendar1
Expand|Select|Wrap|Line Numbers
  1. Private Sub Form_Current() 
  2. Dim rs As Recordset
  3. Dim Db As Database
  4. Dim STRSQL As String
  5.  
  6. If Not Me.rDate Then
  7. Me.Calendar1 = Me.rDate  '<<<<<<<<<<<<<<<<<<Problem???
  8. End If
Dec 7 '07 #9
AdrianGawrys
12 New Member
Adrian,
Just noticed this. Could line 7 be your problem? it looks to me like line 7 is backwards. I think it should be: Me.rDate = Me.Calendar1
Expand|Select|Wrap|Line Numbers
  1. Private Sub Form_Current() 
  2. Dim rs As Recordset
  3. Dim Db As Database
  4. Dim STRSQL As String
  5.  
  6. If Not Me.rDate Then
  7. Me.Calendar1 = Me.rDate  '<<<<<<<<<<<<<<<<<<Problem???
  8. End If
No it's not a problem actually - Calendar is not bound to rDate so if you open form with rota I need Calendar to show what day is the rota for. It's under Form_Current because before I had "move to next" and "move to previous" record selectors so also needed to show what date is the rota for.
Dec 8 '07 #10
AdrianGawrys
12 New Member
Sorry for wasting your time but I manage to find a solution to my problem - I just removed the line where I execute PopulateListBoxes() function after creating new record and put it under AfterInsert() Sub of the form. That seem to fixed my problem - for some reason running my function right after creating new record didnt allow me to address subform's controls - like they haven't been created yet. Now everything seems to be ok.
Dec 11 '07 #11

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

Similar topics

1
by: sixsoccer | last post by:
I have built a database with a <Mainform> and a <Subform>. My problem is twofold. 1. My subform is set as a continuos form with AllowAddiotions set to NO (ie. a list of Issues to the client on...
12
by: MLH | last post by:
I have created two forms: frmBrowseNegsMainform and frmBrowseNegsSubform. I put a subform control on the first of these. The SourceObject property for the subform control is, of course,...
4
by: Dave Boyd | last post by:
Hi, I have two very similar forms each with a subform. The main form gets a few fields from the user and passes this back to a query that the subform is bound to. The requery is done when the...
2
by: F. Michael Miller | last post by:
I need to requery a subform from a third form and can't seem to get it to work. frmForm1 has frmAddress as a subform. The button cmdReviseAddress opens the form frmUpdateAddress where all of my...
14
by: Kurt | last post by:
I have an unbound main form with an unbound subform. frmProjects fsubProjectList Using combo boxes, the user can select several search criteria on frmProjects and then click a command button....
2
by: David W. Fenton | last post by:
I think at various times we've all encountered this problem: A subform is on a main form. From the code of the main form we refer to some property of/control on the child form thus: ...
6
by: MarkoBBC | last post by:
Hi everyone, First a brief description of my form: I have a subform within a main form. In my subform, I have a listbox displaying address information by firm name. A user first has to select a...
9
by: Ecohouse | last post by:
I have a main form with two subforms. The first subform has the child link to the main form identity key. subform1 - Master Field: SK Child Field: TrainingMasterSK The second subform has a...
4
by: Macbane | last post by:
Hi, I have a 'main' form called frmIssues which has a subform control (named linkIssuesDrug) containing the subform sfrmLink_Issues_Drugs. A control button on the main form opens a pop-up form...
11
by: mrowe | last post by:
I am using Access 2003. (I am also using ADO in the vast majority of my code. I recently read a post that indicated that ADO is not all that is was initially cracked up to be. In the back of my...
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...
1
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
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
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
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
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
muto222
php
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.