VBA Date Format

  • Thread starter Thread starter Peter Barker
  • Start date Start date
P

Peter Barker

I get an "Compile error: Can't find project or library" when I use this
code. It should give me a location, depending on the date entered.

[DATE]= #" & Format(Me![Combo67], "MM/DD/YY") & "#;"

The word format is highlighted as the problem. I think the code worked OK
on Access97, but no longer works now I have upgraded to Access 2003.
Advice appreciated
thanks
Peter

The whole event is shown below:

Private Sub Combo67_BeforeUpdate(Cancel As Integer)
Dim SQLStmt, R As Recordset
SQLStmt = "SELECT DISTINCT [DATE] FROM [AIRCRAFT REGISTRATIONS] WHERE
[AIRCRAFT REGISTRATIONS].[DATE] IS NOT NULL;"
Me![LOCATION].RowSource = SQLStmt
Me![LOCATION].Requery
Set R = CurrentDb.OpenRecordset(SQLStmt)
SQLStmt = "SELECT DISTINCT [LOCATION] FROM [AIRCRAFT REGISTRATIONS] WHERE
[AIRCRAFT REGISTRATIONS].[LOCATION] IS NOT NULL AND [AIRCRAFT
REGISTRATIONS].[DATE]= #" & Format(Me![Combo67], "MM/DD/YY") & "#;"
Me![LOCATION].RowSource = SQLStmt
Me![LOCATION].Requery
Set R = CurrentDb.OpenRecordset(SQLStmt)
If R.RecordCount > 0 Then
R.MoveLast
If R.RecordCount = 1 Then
Me![LOCATION] = R![LOCATION]
End If
End If
End Sub
 
Any time an Access application suddenly stops working, the first thing to
suspect is a problem with the References collection.

References problems can be caused by differences in either the location or
file version of certain files between the machine where the application was
developed, and where it's being run (or the file missing completely from the
target machine). Such differences are common when new software is installed.

On the machine(s) where it's not working, open any code module (or open the
Debug Window, using Ctrl-G, provided you haven't selected the "keep debug
window on top" option). Select Tools | References from the menu bar. Examine
all of the selected references.

If any of the selected references have "MISSING:" in front of them, unselect
them, and back out of the dialog. If you really need the reference(s) you
just unselected (you can tell by doing a Compile All Modules), go back in
and reselect them.

If none have "MISSING:", select an additional reference at random, back out
of the dialog, then go back in and unselect the reference you just added. If
that doesn't solve the problem, try to unselect as many of the selected
references as you can (Access may not let you unselect them all), back out
of the dialog, then go back in and reselect the references you just
unselected. (NOTE: write down what the references are before you delete
them, because they'll be in a different order when you go back in)
 
As Douglas has said, it might be references. Whether it is or not, you have
another potential problem:

Date is a Reserved keyword. Using [DATE] as a field name could easily be
causing problems. It might have been possible to "get away" with that in
Access 97 but it was never a good practice, and that may be coming home to
roost.

Even if you get it to run without changing the field name, it is likely to
cause a problem sooner or later and unless you bite the bullet and change it
now you'll never be able to eliminate it from the list of suspects when/if
future problems arise.

HTH,
 
Many thanks
Works fine now.
Peter

Douglas J. Steele said:
Any time an Access application suddenly stops working, the first thing to
suspect is a problem with the References collection.

References problems can be caused by differences in either the location or
file version of certain files between the machine where the application
was developed, and where it's being run (or the file missing completely
from the target machine). Such differences are common when new software is
installed.

On the machine(s) where it's not working, open any code module (or open
the Debug Window, using Ctrl-G, provided you haven't selected the "keep
debug window on top" option). Select Tools | References from the menu bar.
Examine all of the selected references.

If any of the selected references have "MISSING:" in front of them,
unselect them, and back out of the dialog. If you really need the
reference(s) you just unselected (you can tell by doing a Compile All
Modules), go back in and reselect them.

If none have "MISSING:", select an additional reference at random, back
out of the dialog, then go back in and unselect the reference you just
added. If that doesn't solve the problem, try to unselect as many of the
selected references as you can (Access may not let you unselect them all),
back out of the dialog, then go back in and reselect the references you
just unselected. (NOTE: write down what the references are before you
delete them, because they'll be in a different order when you go back in)


--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)



Peter Barker said:
I get an "Compile error: Can't find project or library" when I use this
code. It should give me a location, depending on the date entered.

[DATE]= #" & Format(Me![Combo67], "MM/DD/YY") & "#;"

The word format is highlighted as the problem. I think the code worked
OK
on Access97, but no longer works now I have upgraded to Access 2003.
Advice appreciated
thanks
Peter

The whole event is shown below:

Private Sub Combo67_BeforeUpdate(Cancel As Integer)
Dim SQLStmt, R As Recordset
SQLStmt = "SELECT DISTINCT [DATE] FROM [AIRCRAFT REGISTRATIONS] WHERE
[AIRCRAFT REGISTRATIONS].[DATE] IS NOT NULL;"
Me![LOCATION].RowSource = SQLStmt
Me![LOCATION].Requery
Set R = CurrentDb.OpenRecordset(SQLStmt)
SQLStmt = "SELECT DISTINCT [LOCATION] FROM [AIRCRAFT REGISTRATIONS] WHERE
[AIRCRAFT REGISTRATIONS].[LOCATION] IS NOT NULL AND [AIRCRAFT
REGISTRATIONS].[DATE]= #" & Format(Me![Combo67], "MM/DD/YY") & "#;"
Me![LOCATION].RowSource = SQLStmt
Me![LOCATION].Requery
Set R = CurrentDb.OpenRecordset(SQLStmt)
If R.RecordCount > 0 Then
R.MoveLast
If R.RecordCount = 1 Then
Me![LOCATION] = R![LOCATION]
End If
End If
End Sub
 
Back
Top