Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion GroupsFormsForms ProgrammingQueriesModules / DAO / VBAReports / PrintingMacrosDatabase DesignSecurityConversionImporting / LinkingSQL Server / ADPMultiuser / NetworkingReplicationSetup / ConfigurationDeveloper ToolkitsActiveX ControlsNew UsersGeneral 1General 2
Access DirectoryToolsTutorialsUser Groups
Related Topics
SQL ServerOther DB ProductsMS OfficeMore Topics ...

MS Access Forum / Forms Programming / December 2007

Tip: Looking for answers? Try searching our database.

Need Help with If Statement

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
magmike - 31 Dec 2007 16:43 GMT
The following code runs on Form Current:
----------------------------------------
Private Sub Form_Current()
Dim strSQL As String
Dim db As DAO.Database

   Set db = DBEngine(0)(0)
   strSQL = "INSERT INTO LastVisitedRecord ( lvCompanyID ) " _
               & " VALUES ( " & Me.ID & " ) "
   db.Execute strSQL
   Set db = Nothing

End Sub
----------------------------------------

However, when creating a new record, I receive an error on the INSERT
INTO statement, because there is no value to insert. How would I
construct an If statement with this code. I've messed with it a bit,
but can't seem to get it to work.

Thanks in advance!

magmike
magmike - 31 Dec 2007 16:47 GMT
> The following code runs on Form Current:
> ----------------------------------------
[quoted text clipped - 19 lines]
>
> magmike

I figured it out. I was using If Me.ID Is Null and was getting an
object needed error. I changed it to If Me.ID < 0 and now it works.
Thanks for thinking about helping me though!

magmike
Baz - 31 Dec 2007 16:59 GMT
If IsNull(Me.ID) Then...
Baz - 31 Dec 2007 16:50 GMT
Note the use of the dbFailOnError option with the Execute method (otherwise,
if it fails, it will do so silently):

If Not Me.NewRecord Then
   Set db = DBEngine(0)(0)
   strSQL = "INSERT INTO LastVisitedRecord ( lvCompanyID ) " _
            & " VALUES ( " & Me.ID & " ) "
   db.Execute strSQL, dbFailOnError
   Set db = Nothing
End If

> The following code runs on Form Current:
> ----------------------------------------
[quoted text clipped - 19 lines]
>
> magmike
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.