Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Dlookup problem 2

Status
Not open for further replies.

scottian

Programmer
Jul 3, 2003
955
GB
Im hoping someone can help. The code Im using is:-

------------------------------------
If (DLookup("[Date]", "GasFigures", "[Date]")) = Me![Text235] Then
DoCmd.OpenForm "AllRecords", acNormal, "", "", , acNormal
Else
DoCmd.OpenForm "NewRecord", acNormal, "", "", , acNormal
End If
------------------------------------

on the on click event of a button. i want it to open the all figures form if the date in the text box "text235" matches any record in the GasFigures table. if no match is found then the "NewRecord" form opens instead.

any help is greatly appreciated

 
chirpyform,
sorry i got an error from your hotmail provider, message undeliverable.
i think i'll just have to use a macro. though it loathes me to, as im trying to write evrything in code so get more practice. thanks for your help and ive awarded you both a star.
thanks once again.
 
chris,

got another failure. it must be the attachment
 
Otherwise do it as a normal query:

Create a query in access:
PARAMETERS myDate Date;
SELECT GaasFigures.Date FROM GasFigures WHERE GasFigures.Date = myDate;

Then in the module

Dim db as database
Dim qrd as QueryDefs
Dim rcs as Recordset

Set db = CurrentDb
Set qrd = db.QueryDefs("Your Query")
qrd.Parameters!myDate = Me!text235.Value
set rcs = qrd.openrecordset

if rcs.recordCount <> 0 then
DoCmd.OpenForm &quot;AllRecords&quot;, acNormal, &quot;&quot;, &quot;&quot;, , acNormal
Else
DoCmd.OpenForm &quot;NewRecord&quot;, acNormal, &quot;&quot;, &quot;&quot;, , acNormal
End If



 
If you use the access debugger ie click on the side of the window alongside the line
Set db = CurrentDb
then when the code runs you can use the F8 key to see where the error is and you could try adding
&quot;# &quot; & Me!text235.Value & &quot; #&quot;
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top