A Microsoft Office (Excel, Word) forum. OfficeFrustration

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   Home » OfficeFrustration forum » Microsoft Access » Using Forms
Site Map Home Register Authors List Search Today's Posts Mark Forums Read  

Help Using DlookUp on a Form



 
 
Thread Tools Display Modes
  #1  
Old September 22nd, 2005, 01:33 AM
Radar
external usenet poster
 
Posts: n/a
Default Help Using DlookUp on a Form

Need help with DLookup in forms beforeupdate
I have a table called tblStoreOrders with a key field name [Store] ( a
numeric field)
My form name is frmStoreOrders with a combo box call "Store" (This has
all the availible store numbers)
I want to check to see if this store has already placed an on the
same date. or a duplicate record, based on the same date of entry.
I tried first just looking for the store only. no luck.

DLookup("[Store]", "[tblStoreOrders]", "[Store] =
Forms![frmstoreOrders!store]")
error Expecting =
Please Help!
  #2  
Old September 22nd, 2005, 02:24 AM
Tom Lake
external usenet poster
 
Posts: n/a
Default


"Radar" wrote in message
...
Need help with DLookup in forms beforeupdate
I have a table called tblStoreOrders with a key field name [Store] ( a
numeric field)
My form name is frmStoreOrders with a combo box call "Store" (This has
all the availible store numbers)
I want to check to see if this store has already placed an on the
same date. or a duplicate record, based on the same date of entry.
I tried first just looking for the store only. no luck.

DLookup("[Store]", "[tblStoreOrders]", "[Store] =
Forms![frmstoreOrders!store]")
error Expecting =
Please Help!


If store is numeric, try this:

DLookup("[Store]", "[tblStoreOrders]", "[Store] =" &
Forms![frmstoreOrders!store])

If it's text, try this:

DLookup("[Store]", "[tblStoreOrders]", "[Store] = '" &
Forms![frmstoreOrders!store] & "'")

Tom Lake


  #3  
Old September 22nd, 2005, 04:44 AM
John Vinson
external usenet poster
 
Posts: n/a
Default

On Wed, 21 Sep 2005 21:24:54 -0400, "Tom Lake"
wrote:

If store is numeric, try this:


One of the other problems is the brackets: should be

[Forms]![frmOrders]![Store]

John W. Vinson[MVP]
  #4  
Old September 24th, 2005, 03:01 PM
Radar
external usenet poster
 
Posts: n/a
Default


Ok guys for give me. I now that I don't know as much as I thought.
I've tried different methods and I am knot sure how to write the code.
I even tried strStore = Dlookup()
What I need is, if the data or store already exist then, I need for
that record to apear, if not then alow then entry.
I don't know if I should put the code on the forms beforeupdate or the
[Store] 's beforupdate
Please help guys'
Thanks


On Wed, 21 Sep 2005 21:24:54 -0400, "Tom Lake"
wrote:


"Radar" wrote in message
.. .
Need help with DLookup in forms beforeupdate
I have a table called tblStoreOrders with a key field name [Store] ( a
numeric field)
My form name is frmStoreOrders with a combo box call "Store" (This has
all the availible store numbers)
I want to check to see if this store has already placed an on the
same date. or a duplicate record, based on the same date of entry.
I tried first just looking for the store only. no luck.

DLookup("[Store]", "[tblStoreOrders]", "[Store] =
Forms![frmstoreOrders!store]")
error Expecting =
Please Help!


If store is numeric, try this:

DLookup("[Store]", "[tblStoreOrders]", "[Store] =" &
Forms![frmstoreOrders!store])

If it's text, try this:

DLookup("[Store]", "[tblStoreOrders]", "[Store] = '" &
Forms![frmstoreOrders!store] & "'")

Tom Lake


  #5  
Old September 25th, 2005, 03:35 AM
John Vinson
external usenet poster
 
Posts: n/a
Default

On Sat, 24 Sep 2005 14:01:23 GMT, Radar wrote:


Ok guys for give me. I now that I don't know as much as I thought.
I've tried different methods and I am knot sure how to write the code.
I even tried strStore = Dlookup()
What I need is, if the data or store already exist then, I need for
that record to apear, if not then alow then entry.
I don't know if I should put the code on the forms beforeupdate or the
[Store] 's beforupdate
Please help guys'
Thanks


Which event is appropriate depends on the context. If the user enters
a store (?) into a textbox, do they need to be warned right then,
before entering the rest of the record? If so, use the Store control's
BeforeUpdate event. Or is it a unique *record* that's important? If
so, use the Form's BeforeUpdate.

In either case the logic is similar: attempt to look up the value
which should be unique; if the lookup finds nothing, DLookUp will
return NULL and all is well. If it finds something, it isn't NULL and
you need to warn the user and Cancel the update. In the case of a Form
you'ld do something like this (I'm assuming that Store is a text field
hence the ' delimiters):

Private Sub Form_BeforeUpdate(Cancel as Integer)
If Not IsNull(DLookUp("[Store]", "[tablename]", _
"[Store] = '" & Me!txtStore & "'") Then
MsgBox "This store already exists", vbOKOnly
Cancel = True ' Cancel the addition of this record
Me.Undo ' erase the form
OR
Me!txtStore.Undo ' just erase the Store field
End If
End Sub


John W. Vinson[MVP]
 




Thread Tools
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

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Need Help In Printing Current Record in Specific Report RNUSZ@OKDPS Setting Up & Running Reports 1 May 16th, 2005 09:06 PM
Dlookup works on Form but not on Report LoriFromBuffalo Setting Up & Running Reports 2 April 12th, 2005 09:55 PM
Design help, please SillySally Using Forms 27 March 6th, 2005 04:11 AM
Default values to load up automatically in a form based on value entered in another form Anthony Dowd Using Forms 8 August 12th, 2004 08:53 AM
auto entry into second table after update Tony New Users 13 July 9th, 2004 10:42 PM


All times are GMT +1. The time now is 05:18 AM.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 OfficeFrustration.
The comments are property of their posters.