Ok the problem originally started with me wanting to compare the dates entered on one form with the dates entered on a different form's subform (I hope that wasn't too confusing). Thru numerous trials and error, I discovered that it was not possible to do it this way since 1) the other subform had to be open and 2) the main form of the searchee subform had to be on the correct record already (headache!).
Then I stumbled onto recordsets. I think I've found the solution. However I have a few concerns. - Do I use a DAO recordset or an ADO recordset (just trying to access a table and compare its values to some VB variables)
- Is my syntax correct for the query
- Why is it coming back with an empty recordset?
-
Private Sub txtDistributionDate_LostFocus()
-
Dim rs As DAO.Recordset
-
Dim DB As DAO.Database
-
Dim tempDate As Date
-
Dim tempFieldID, strSQL As String
-
-
Set DB = CurrentDb()
-
-
Me.cboFoodDonationsID.SetFocus
-
tempFieldID = Me.cboFoodDonationsID.Text
-
MsgBox tempFieldID, vbOKOnly
-
-
-
Set rs = DB.OpenRecordset("SELECT Date FROM tblFoodDonations WHERE [tblFoodDonations]![FoodDonationsID] ='" & tempFieldID & " ' ")
-
rs.MoveFirst
-
-
Do While Not rs.EOF
-
rs.MoveNext
-
'TEST to see the current seached record
-
MsgBox rs("FoodDonationsID").Value + rs("Date").Value, vbOKOnly
-
-
Loop
-
tempDate = rs("Date").Value
-
-
-
-
If Me.txtDistributionDate > tempDate Then
-
MsgBox "Please enter a date that is after the product was Donated!", vbExclamation, "Date Check"
-
-
-
-
Me.txtDistributionDate.SetFocus
-
-
End If
-
-
rs.Close
-
-
End Sub
-
Thank you in advanced for your help!
Aug 10 '07
33 9867
Three things I notice here:
Number one is that you have declared your tempFieldID as String. This should be Integer or Long because you are comparing it (presumably that is, unless you have made your ID fields alphanumeric) to a number field later on.
Number two is that you are missing a space between [FoodDonationsID] and the = sign.
Number three is you still need to correctly rename your txtDistribution Date field to Me.txtDistribut ionDate
Make these changes and try again. (btw I hope you are remembering to compile your changes, save your changes and recheck compile status during this process. If you don't, you likely won't notice the warning signs of corruption until it's almost too late!)
Regards,
Scott
Thanks for all your help so far Scott, I really really do appreciate it because this thing has been bugging me for a week and a half.
So I've fixed number 2 and 3 but the tempField is a string because although we would rather not some of our receipts are alphanumeric due to our printing company giving us rerun numbers of our paper receipts. This isn't caught until data entry time so we're forced to add a letter to the end of the FoodDonationsID on the receipt (both on paper and on screen for consistency). -
Private Sub txtDistributionDate_AfterUpdate()
-
Dim tempFieldID As String
-
Dim frmFoodDonationbyDate As Form
-
-
Me.cboFoodDonationsID.SetFocus
-
tempFieldID = Me.cboFoodDonationsID.Value
-
-
(A)-> DoCmd.OpenForm "frmFoodDonationbyDate", , , "[frmFoodDonationbyDate]![FoodDonationsID] =" & tempFieldID, , acHidden
-
DoCmd.Requery
-
-
(B)->If [frmFoodDonationbyDate]![txtDonDate] > Me.txtDistributionDate Then
-
MsgBox "Please enter a Delivery date that is after that of the date of Donation!", vbOKOnly, "Out of Range Date Exception"
-
Me.txtDistributionDate.SetFocus
-
End If
-
-
DoCmd.Close acForm, "frmFoodDonationbyDate"
-
End Sub
-
I'm no longer receiving an error at arrow A but there is a pop-up box that requests this member when the comparison runs: [frmFoodDonation byDate]![FoodDonationsID]
I'm only testing one receipt number = 56846 and I've found it on the query and on the form. I'm wondering if it is not being found because the form is hidden?
The issue at arrow B is that when I mouse over it in the VBA code I'm not seeing a value for it like I should. I of course see the correct value for txtDistribution Date.
Let's take care of A first, and then see if B still is a problem.
In your DoCmd.OpenForm statement, you have already referred to the form you want to open, so later in your Where clause, you don't need to refer to it again... It's sufficient to simply point to the field you are comparing. I.e. instead of "[frmFoodDonation byDate]![FoodDonationsID] =", it's enough to just put in: "[FoodDonationsID] =" &...
If both fields are string values, then you shouldn't have any trouble comparing them the way you have it set up. The trouble starts if you try to compare a string field with a number field.
One quick question that occurs: is the ReceiptID field the primary key of your table? If so, have you taken steps to make sure that it is, in fact, unique (i.e. there can never be duplicates in this field?)
You will end up with potentially inaccurate data if your answer to question two is no :-) What can happen is that if you are telling the db to open this hidden test form looking for a particular ReceiptID, and there are multiple instances of it, you will unknowingly be testing your date against what is possibly the wrong ReceiptID/Date combination because the test date will be the date entered for the FIRST record that is returned. This is because the other records will be on the form, but in single form view you can only see one record at a time...
Regards,
Scott
Oh man sorry for potentially confusing the issue Scott. The receipt ID is the FoodDonationsID I was just referring to it with a generic term. Anyway the FoodDonationsID is alphanumeric as is the tempFieldID.
The table from which the query for the hidden form draws data (tblFoodDonatio ns) has the FoodDonationID as the unique identifier so there are NO duplicates.
That was the issue before. When I referred to it as just [FoodDonationsID] I received a runtime error 2501. But when I put in [frmFoodDonation byDate]![FoodDonationsID] I did not receive this error, I just did not receive a value for the txtDonDate.
Oh man sorry for potentially confusing the issue Scott. The receipt ID is the FoodDonationsID I was just referring to it with a generic term. Anyway the FoodDonationsID is alphanumeric as is the tempFieldID.
The table from which the query for the hidden form draws data (tblFoodDonatio ns) has the FoodDonationID as the unique identifier so there are NO duplicates.
That was the issue before. When I referred to it as just [FoodDonationsID] I received a runtime error 2501. But when I put in [frmFoodDonation byDate]![FoodDonationsID] I did not receive this error, I just did not receive a value for the txtDonDate.
No problem! I wasn't too confused, anyway :-) So is it working now?
Just to clarify, in your DoCmd statement to open the form, you need to refer to the Form control name, not the Table field name: i.e. txtFoodDonation sID > FoodDonationsID .
Regards,
Scott
Just went back and looked, and I see you were talking about subforms earlier!
Perchance is the txtDistribution Date control that you are referring to part of the subform?
If so, you need to refer to it by it's full name: i.e. Forms![YourMainFormNam e]![YourSubFormName].[ControlNameOnSu bForm]
If, also your cboFoodDonation sID is part of the same subform, it also needs to be referred to by it's full name, as described above.
See the following changes I've made to your code. -
Private Sub txtDistributionDate_AfterUpdate()
-
Dim tempFieldID As String
-
Dim frmFoodDonationbyDate As Form
-
-
Me.cboFoodDonationsID.SetFocus
-
tempFieldID = Me.cboFoodDonationsID.Value
-
-
(A)-> DoCmd.OpenForm "frmFoodDonationbyDate", , , "[FoodDonationsID] =" & tempFieldID, , acHidden
-
DoCmd.Requery
-
-
(B)->If [frmFoodDonationbyDate]![txtDonDate] > Forms![YourMainFormName]![YourSubformName].txtDistributionDate Then
-
MsgBox "Please enter a Delivery date that is after that of the date of Donation!", vbOKOnly, "Out of Range Date Exception"
-
Me.txtDistributionDate.SetFocus
-
End If
-
-
DoCmd.Close acForm, "frmFoodDonationbyDate"
-
End Sub
Regards,
Scott
No problem! I wasn't too confused, anyway :-) So is it working now?
Just to clarify, in your DoCmd statement to open the form, you need to refer to the Form control name, not the Table field name: i.e. txtFoodDonation sID > FoodDonationsID .
Regards,
Scott
No it's not working yet unfortunately. To clarify things further when I created the new third hidden form, I made it a (tabular?) form I believe, and the control name is the same name as the control source. Name: FoodDonationsID ; Control Source: FoodDonationsID .
I'm not sure if this frmAgencyDonati on is a subform or not because as it stands data is being passed thru the code as it is. When I mouse over it in debug VBA code I do see the correct data. However when I mouse over the code for the hidden form nothing displays.
No it's not working yet unfortunately. To clarify things further when I created the new third hidden form, I made it a (tabular?) form I believe, and the control name is the same name as the control source. Name: FoodDonationsID ; Control Source: FoodDonationsID .
I'm not sure if this frmAgencyDonati on is a subform or not because as it stands data is being passed thru the code as it is. When I mouse over it in debug VBA code I do see the correct data. However when I mouse over the code for the hidden form nothing displays.
Go into your hidden form in design view and change it to single form view.
Once in design view, double click on the little square on the upper left of the design view window, which brings up the Properties for your form. A few lines down on the All tab is the setting to change to Single form view.
If the data is being passed from your frmAgencyDonati on, then it isn't a subform :-)
Regards,
Scott
Go into your hidden form in design view and change it to single form view.
Once in design view, double click on the little square on the upper left of the design view window, which brings up the Properties for your form. A few lines down on the All tab is the setting to change to Single form view.
If the data is being passed from your frmAgencyDonati on, then it isn't a subform :-)
Regards,
Scott
Ok I've finally managed to get a different error. Maybe this is where the ADO vs. DAO stuff comes into play (code changes will be underlined). The hidden form is in single form view.
[ERROR]
Run-Time error: 429
Active X object cannot be created
[/ERROR]
( -> ) will refer to error line. -
Private Sub txtDistributionDate_AfterUpdate()
-
Dim tempFieldID As String
-
Dim frmFoodDonationbyDate As New Form
-
-
Me.cboFoodDonationsID.SetFocus
-
tempFieldID = Me.cboFoodDonationsID.Value
-
-
-> DoCmd.OpenForm "frmFoodDonationbyDate", , , [frmFoodDonationbyDate]![FoodDonationsID] & "=" & tempFieldID, , acHidden
-
DoCmd.Requery
-
-
If [frmFoodDonationbyDate]![txtDonDate] > Me.txtDistributionDate Then
-
MsgBox "Please enter a Delivery date that is after that of the date of Donation!", vbOKOnly, "Out of Range Date Exception"
-
Me.txtDistributionDate.SetFocus
-
End If
-
-
DoCmd.Close acForm, "frmFoodDonationbyDate"
-
End Sub
-
I removed the NEW from in front of Form at the top and now I'm just receiving the run-time error 91: Object variable or with not set. It occurs at the arrow still
If the form already exists there is absolutely no reason to dim it as a new form!
The reason you are getting the error you are getting now is that you've tried to recreate a form that already exists!
To backup a little, let's assume that you have based your hidden form on a query. The query looks a little like this: - SELECT tblFoodDonations.FoodDonationsID, tblFoodDonations.DonationDate FROM tblFoodDonations WHERE tblFoodDonations.DonationsID = Forms!frmFoodDonations.FoodDonationsID
Now you can do away with the where clause in your DoCmd.OpenForm line. It will then look something like this: - DoCmd.OpenForm "frmFoodDonationbyDate", , , , , acHidden
It looks like you've been making changes unnecessarily when one or another thing hasn't worked! It's good to try different things in most cases, but unfortunately you've only been managing to introduce other opportunities for error :-( I commend you for working at this, and I appreciate that you're willing to try different approaches. Don't give up yet!
There is no reason to change the DoCmd.OpenForm syntax from what I have posted... The syntax isn't the problem at this point.
Let me know what you have based your hidden form on, and let's go from there.
Regards,
Scott
...
It looks like you've been making changes unnecessarily when one or another thing hasn't worked! It's good to try different things in most cases, but unfortunately you've only been managing to introduce other opportunities for error :-( I commend you for working at this, and I appreciate that you're willing to try different approaches. Don't give up yet!
There is no reason to change the DoCmd.OpenForm syntax from what I have posted... The syntax isn't the problem at this point.
Let me know what you have based your hidden form on, and let's go from there.
Regards,
Scott
Thanks for sticking it out with me up to this point Scott, I really and truly appreciate it. As you can tell I haven't worked to heavily in the forms and controls side of Access, I'm usually tinkering with the raw tables and queries.
Anyway the hidden form is based on a simple query to the foodDonations table. -
SELECT tblFoodDonations.FoodDonationsID, tblFoodDonations.Date
-
FROM tblFoodDonations;
-
Sign in to post your reply or Sign up for a free account.
Similar topics |
by: Matt Young |
last post by:
I've been tasked with integrating an older management system based on
DBF files with my snappy new ASP application to provide users of the
ASP application with real-time data from the management system.
I figure with DBF files, I should use either the DBase drivers or the
FoxPro drivers to connect to the database.
The integration has gone quite smoothly until yesterday. This means
that my connection strings work well based on the...
|
by: Bruno Alexandre |
last post by:
Hi guys,
withou using SP, I want to be able to add a Parameter to the SQL Query and
retrive the Recordset so I can use the Paging property under the recorset
object.... how can I do this?
I'm stuck here.
|
by: dmiller23462 |
last post by:
My brain is nuked....Can anybody tell me right off the bat what is
wrong with this code? Along with any glaring errors, please let me
know the syntax to display a message (Response.Write would be fine I
think) that will say "I'm sorry but the data you requested cannot be
found" or something along those lines....
This code is on an archive page I have on my company's intranet....The
end result is to show 3 records at a time pulled from an...
|
by: tabonni |
last post by:
Hi All
I connected MS Exchange Server to MS Access database using Access link
table function. I can open the database table and see the fields and
data inside the link table. However, the table seems cannot be queried
by SQL statement.
My situation is:
I'm building an intranet. I have a ASP login page for all staff in the
company to login. Other people can't register or login the intranet.
|
by: Dom Boyce |
last post by:
Hi
First up, I am using MS Access 2002.
I have a database which records analyst rating changes for a list of
companies on a daily basis. Unfortunately, the database has been set
up (by my predecessor, I hasten to add) so that each day it creates a
copy of the record for each company, changes the date to today's date,
and prompts the user for any changes of ratings on that day. The
resulting data table grows by approx 600 records per...
| |
by: lenny |
last post by:
Hi,
I've been trying to use a Sub or Function in VBA to connect to a
database, make a query and return the recordset that results from the
query. The connection to the database and the query works fine, but
passing the resulting recordset back to the sub's caller is not working
out.
|
by: Bill R via AccessMonster.com |
last post by:
I get the error msg "Object variable or With block variable not set" when
closing the "persistent" recordset I opened when the application opened.
I have the rs variable declared in the declarations section of a module:
Public rsAlwaysOpen As DAO.Recordset
Then, when the switchboard form loads I set the variable:
|
by: Jim M |
last post by:
I rarely deal with recordsets directly with code, since I usually use
Access queries, so be patient with this question. I want to open a
recordset with various default variables used by my program. I tried:
Public Sub OpenDefaults()
Dim db As dao.Database
Dim globalRst As dao.Recordset
Set db = CurrentDb()
Set globalRst = db.OpenRecordset("tblDefaults")
End Sub
|
by: wallconor |
last post by:
Hi,
I am having a problem using Dreamweaver CS3 standard recordset paging behavior. It doesn’t seem to work when I pass parameter values from a FORM on my search page, to the recordset on my results page.
- Recordset Paging works if no parameters are used in the recordset sql code (ie. simple sql code):
SELECT *
FROM db_name
WHERE (db_field1 LIKE ‘%text1%’ OR db_field2 LIKE ‘%text2%’)
|
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
|
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
| |
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
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 then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |