If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > PC based Database Applications > Microsoft Access > DLookup only returning first value from table

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #16 (permalink)  
Old 10-28-11, 08:02
Mohamedk Mohamedk is offline
Registered User
 
Join Date: Sep 2011
Posts: 28
Hi Pbaldy

Thanks for your help

I have tried your suggestion but I get the error

"Item not found in this collection".

My code is below

Private Sub Command115_Click()
Dim db As Database
Dim rs As Recordset
Set db = CurrentDb()
Set rs = CurrentDb.OpenRecordset("SELECT [Password] FROM [tblpasswords] WHERE [Used] = 0")
With rs
Me.lngEncrpytion_Password = ![Password]
.Edit
![Password used] = True
.Update
.MoveNext
End With
End Sub

The line it highlights in debug mode is

![Password used] = True


Any ideas?

Thanks
Reply With Quote
  #17 (permalink)  
Old 10-28-11, 11:09
pbaldy pbaldy is offline
Registered User
 
Join Date: May 2005
Location: Nevada, USA
Posts: 2,475
Sure; you have to add that field to the SELECT clause for the recordset.
Reply With Quote
  #18 (permalink)  
Old 10-28-11, 11:18
Mohamedk Mohamedk is offline
Registered User
 
Join Date: Sep 2011
Posts: 28
Thanks again

Sorry but do you mind telling me the code to do this.

Thanks
Reply With Quote
  #19 (permalink)  
Old 10-28-11, 11:34
healdem healdem is offline
Jaded Developer
 
Join Date: Nov 2004
Location: out on a limb
Posts: 9,250
surely wouldn't you be better off using SQL for this
there seems little point interrating through a records set if all you want to do is update
UPDATE tblpasswords] set [password used] = true WHERE [Used] = 0"
__________________
I'd rather be riding my Versys or my Tiger 800 let alone the Norton
Reply With Quote
  #20 (permalink)  
Old 10-28-11, 12:35
pbaldy pbaldy is offline
Registered User
 
Join Date: May 2005
Location: Nevada, USA
Posts: 2,475
Quote:
Originally Posted by Mohamedk View Post
Sorry but do you mind telling me the code to do this.
Set rs = CurrentDb.OpenRecordset("SELECT [Password], [Password used] FROM [tblpasswords] WHERE [Used] = 0")
__________________
Paul
Reply With Quote
  #21 (permalink)  
Old 10-28-11, 12:37
pbaldy pbaldy is offline
Registered User
 
Join Date: May 2005
Location: Nevada, USA
Posts: 2,475
healdem, given that the goal is to first get an unused password, then flag it as used, the recordset seems appropriate to me. Your SQL would flag all as used.
__________________
Paul
Reply With Quote
  #22 (permalink)  
Old 10-31-11, 06:28
Mohamedk Mohamedk is offline
Registered User
 
Join Date: Sep 2011
Posts: 28
Healdem and Pbaldy....

THANK YOU!

Thanks for all your help. I have managed to get my database working like how I want it.
Reply With Quote
  #23 (permalink)  
Old 10-31-11, 10:52
pbaldy pbaldy is offline
Registered User
 
Join Date: May 2005
Location: Nevada, USA
Posts: 2,475
Happy to help!
Reply With Quote
  #24 (permalink)  
Old 10-31-11, 12:54
healdem healdem is offline
Jaded Developer
 
Join Date: Nov 2004
Location: out on a limb
Posts: 9,250
Quote:
Originally Posted by pbaldy View Post
healdem, given that the goal is to first get an unused password, then flag it as used, the recordset seems appropriate to me. Your SQL would flag all as used.
true
but if the object is to get a single password (the next available one, then you have some code that gets it. you then have sufficient informatiuon to update with a WHERE clause. there should be no need to iterate through a record set to rediscover the correct row in the password table.

heck he could edit the column in the recordset that retrieved the password.
__________________
I'd rather be riding my Versys or my Tiger 800 let alone the Norton
Reply With Quote
  #25 (permalink)  
Old 10-31-11, 13:04
pbaldy pbaldy is offline
Registered User
 
Join Date: May 2005
Location: Nevada, USA
Posts: 2,475
Quote:
Originally Posted by healdem View Post
heck he could edit the column in the recordset that retrieved the password.
I believe that's exactly what's being done:

Me.lngEncrpytion_Password = ![Password]
.Edit
![Password used] = True
.Update

The first line gets the password, the next 3 edit the other field. I grant you that the .MoveNext is confusing, and shouldn't be in there. It may even cause an error. There is no loop.
__________________
Paul
Reply With Quote
  #26 (permalink)  
Old 10-31-11, 13:18
healdem healdem is offline
Jaded Developer
 
Join Date: Nov 2004
Location: out on a limb
Posts: 9,250
fairy snuff
saw the .movenext and assumed the worst......
__________________
I'd rather be riding my Versys or my Tiger 800 let alone the Norton
Reply With Quote
Reply

Tags
dlookup, recordset

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On