Code not running

  • Thread starter Thread starter Phoebe
  • Start date Start date
P

Phoebe

Guest
Hello!

Below code doesn't seem to be running. Can someone help ??

I had created a new form putting 2 textboxes : 1 to rep startdate & another to rep enddate, 1 command button to perform the below function and a text to display all orders from order table.

I too need to ensure that the enddate is not before startdate.

Please help, anyone ??


Private Sub Button_Click
DIM STRSQL AS STRING
DIM STRSTARTDATE AS STRING
DIM STRENDDATE AS STRING

IF NOT ISDATE(ME.TXTSTARTDATE)
ENDIF
IF ISNULL(ME.TXTSTARTDATE)
ENDIF
IF ENDDATE < STARTDATE
STRSTARTDATE=ME.TXTSTARTDATE

STRSQL="SELECT * FROM ORDER
WHERE " & _ STRSTARTDATE &
"# AND #"
ME.LABEL.CAPTION=STRSQL

END SUB

Thank You.
 
I haven't looked in detail at what the code is trying to do, but you don't seem to have an instruction telling access to execute STRSQL, such as:

Db.Execute STRSQL

For this to work you will also have had to declare Db as a database and set it as the current database like:

Dim Dd As Database
set Db = CurrentDb()

Also, do you really mean to put the contents (not results) of STRSQL into the caption of one of your form objects?

HTH

Mike

[This message has been edited by Mike Gurman (edited 10-04-2000).]
 
Probably your SQL does not run - did you abbreviate??

First:
Your SQL does not contain FROM TableName nor ORDER BY FieldNameWithSortCriteria - therefore it won't work at all.

Second:
Try this:

Dim rs AS Recordset
Set rs=dB.OpenRecordset(STRSQL)
ME.LABEL.CAPTION=rs!FieldNameContainingDataForCaption
set rs=nothing

Programming with access to tables is not that easy - sorry!
 

Users who are viewing this thread

Back
Top Bottom