Addnew, based on IF in loop - problem

C.D

Registered User.
Local time
Today, 23:08
Joined
Sep 29, 2007
Messages
42
Good day,
I'm trying to make a combined newrecord/update button for adding episodes to series, but it won't work.
Code:
Private Sub EpUpdater_Click()
  Dim db            As DAO.Database
  Dim rs            As DAO.Recordset
  Dim x             As Long

  Set db = CurrentDb()

  Set rs = db.OpenRecordset("tblAnimeEpisode", dbOpenDynaset)

  For x = Me.txtStart To Me.txtEnd
        If DCount("AnimeEpisodeID", "tblAnimeEpisode", "AnimID=" & [AnimeID] & " AND EpID=x") = 0 Then
            rs.AddNew
            rs!AnimID = Me.AnimeID
            rs!EpID = x
            rs.Update
        End If
    Next x
  
  
  MsgBox "Process complete"
  
  Set rs = Nothing
  Set db = Nothing
End Sub
Thanks to pbaldy for supplying me with the basis of the code

Any help is deeply appreciated :)
 
You need to concatenate the x the same way you did [AnimeID], so it's value can be interpreted for use in the formula.
 
Try putting x outside of the quotes as well:
Code:
If DCount("AnimeEpisodeID", "tblAnimeEpisode", _
   "[AnimID] =" & [AnimeID] & " AND [EpID] =" x) = 0 Then
 
You need to concatenate the x the same way you did [AnimeID], so it's value can be interpreted for use in the formula.
Yay! That worked perfectly! I thought I had done the IF and End If wrong.
This is really cool, and I never have to manually add episodes ever again :D

Thanks alot, Paul!
 

Users who are viewing this thread

Back
Top Bottom