|
-
May 26th, 2005, 11:45 AM
#1
Thread Starter
Addicted Member
Finding the last similar record... [Resolved]
I have an app that deals with ording supplies..
Now when someone chooses the item the want to order I want to display the date this item was last orderd..
I've looked up records before with no problem, but usually a record using a specific item of data specified by the user...
this time i need to find the last entered record with similar criteria.
Last edited by DKasler; May 31st, 2005 at 01:02 PM.
-----MY SITES-----
BayRidgeNights.Com - NYC Nightlife Forums
Fight Communism - Rate Posts!
-
May 26th, 2005, 11:48 AM
#2
Re: Finding the last similar record...
How about something like
VB Code:
strSQL = "SELECT MAX(datefield) FROM table WHERE field = '" & item_that_was_just_ordered & "'"
-
May 26th, 2005, 12:49 PM
#3
Thread Starter
Addicted Member
Re: Finding the last similar record...
i think that could work... Thanks much.
-----MY SITES-----
BayRidgeNights.Com - NYC Nightlife Forums
Fight Communism - Rate Posts!
-
May 26th, 2005, 12:58 PM
#4
Thread Starter
Addicted Member
Re: Finding the last similar record...
How would that be inputed to a label once its called... I tried
VB Code:
Label17.Caption = datPrimaryRs![Max(SupDate)]
but got this error "Item could not be found in the collection corresponding to the requested name or ordinal"
I also tried the about code with out the MAX()
Here is the complete code I used.
VB Code:
Dim sConnect As String
Dim sSQL As String
Dim dfwConn As ADODB.Connection
Dim datPrimaryRs
' set strings
sConnect = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=M:\supplies\supplies.mdb;Persist Security Info=False"
sSQL = "select MAX(SupDate) from SupplyMaster where SupType = '" & DBCombo2.Text & "'"
' open connection
Set dfwConn = New ADODB.Connection
dfwConn.Open sConnect
' create a recordset using the provided collection
Set datPrimaryRs = New ADODB.Recordset
datPrimaryRs.CursorLocation = adUseClient
datPrimaryRs.Open sSQL, dfwConn, adOpenForwardOnly, adLockReadOnly
If IsNull(datPrimaryRs![MAX(SupDate)]) Then
Label17.Caption = "Never Ordered"
Else
Label17.Caption = datPrimaryRs![MAX(SupDate)]
End If
-----MY SITES-----
BayRidgeNights.Com - NYC Nightlife Forums
Fight Communism - Rate Posts!
-
May 26th, 2005, 01:05 PM
#5
Re: Finding the last similar record...
You don't need the MAX in the if statement.
VB Code:
If IsNull(datPrimaryRs![SupDate]) Then
Label17.Caption = "Never Ordered"
Else
Label17.Caption = datPrimaryRs![SupDate]
End If
-
May 26th, 2005, 01:13 PM
#6
Thread Starter
Addicted Member
Re: Finding the last similar record...
I removed the Max from the if statement and Im still getting the same error.
-----MY SITES-----
BayRidgeNights.Com - NYC Nightlife Forums
Fight Communism - Rate Posts!
-
May 26th, 2005, 01:26 PM
#7
Re: Finding the last similar record...
Try ' where 0 is the position in your recordset
-
May 26th, 2005, 02:08 PM
#8
Thread Starter
Addicted Member
Re: Finding the last similar record...
Im not 100% sure where the
needs to go. Though I did try it to the best of my ability and i got the same error as before.
-----MY SITES-----
BayRidgeNights.Com - NYC Nightlife Forums
Fight Communism - Rate Posts!
-
May 31st, 2005, 10:30 AM
#9
Thread Starter
Addicted Member
Re: Finding the last similar record...
like... *bump* - for suuurrre.
-----MY SITES-----
BayRidgeNights.Com - NYC Nightlife Forums
Fight Communism - Rate Posts!
-
May 31st, 2005, 10:37 AM
#10
Re: Finding the last similar record...
Label17.Caption = sSQL(supdate)
try it, i'm not sure
pete
-
May 31st, 2005, 10:44 AM
#11
Thread Starter
Addicted Member
Re: Finding the last similar record...
 Originally Posted by westconn1
Label17.Caption = sSQL(supdate)
try it, i'm not sure
pete
No, that didnt do it either. It just told me that the variable "supdate" was not defined.
On a side note, I even tried changing the field in the db to a date/time field and that made no difference.
Last edited by DKasler; May 31st, 2005 at 10:48 AM.
-----MY SITES-----
BayRidgeNights.Com - NYC Nightlife Forums
Fight Communism - Rate Posts!
-
May 31st, 2005, 10:53 AM
#12
Re: Finding the last similar record...
i would think that sSQL should return only one record which must have must have the date in it you want, so it is just a matter off getting it out.
put a breakpoint in your code just after you get sSQL, then have a look in the locals window at how it is made up, i presume it should be an array of fields
pete
-
May 31st, 2005, 11:25 AM
#13
Fanatic Member
Re: Finding the last similar record...
 Originally Posted by DKasler
How would that be inputed to a label once its called... I tried
VB Code:
Label17.Caption = datPrimaryRs![Max(SupDate)]
but got this error "Item could not be found in the collection corresponding to the requested name or ordinal"
I also tried the about code with out the MAX()
Here is the complete code I used.
VB Code:
Dim sConnect As String
Dim sSQL As String
Dim dfwConn As ADODB.Connection
Dim datPrimaryRs
' set strings
sConnect = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=M:\supplies\supplies.mdb;Persist Security Info=False"
sSQL = "select MAX(SupDate) from SupplyMaster where SupType = '" & DBCombo2.Text & "'"
' open connection
Set dfwConn = New ADODB.Connection
dfwConn.Open sConnect
' create a recordset using the provided collection
Set datPrimaryRs = New ADODB.Recordset
datPrimaryRs.CursorLocation = adUseClient
datPrimaryRs.Open sSQL, dfwConn, adOpenForwardOnly, adLockReadOnly
If IsNull(datPrimaryRs![MAX(SupDate)]) Then
Label17.Caption = "Never Ordered"
Else
Label17.Caption = datPrimaryRs![MAX(SupDate)]
End If
This has worked for me in the previous programs
VB Code:
If IsNull(datPrimaryRs(0)) then
Label17.caption = "Never Ordered"
Else
Label17.Caption = datPrimaryRs(0)
end if
I'm not sure why you have the "!" in there
HTH
Last edited by space_monkey; May 31st, 2005 at 11:33 AM.
Using VB6 or VB.net 2008 with .net 3.5
"Life... death... either way I'll be confined to a small cubicle!" - Hermes Conrad
-
May 31st, 2005, 12:12 PM
#14
Thread Starter
Addicted Member
Re: Finding the last similar record...
 Originally Posted by space_monkey
This has worked for me in the previous programs
VB Code:
If IsNull(datPrimaryRs(0)) then
Label17.caption = "Never Ordered"
Else
Label17.Caption = datPrimaryRs(0)
end if
I'm not sure why you have the "!" in there
HTH
Thank you so much space monkey. That worked just the way I had hoped.
As for the "!" if you dont have it the system expects the end of statement to be "datprimaryRS" so you need the "!" to add the field after
-----MY SITES-----
BayRidgeNights.Com - NYC Nightlife Forums
Fight Communism - Rate Posts!
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|