Results 1 to 6 of 6
  1. #1
    EBG is offline Novice
    Windows 7 64bit Access 2016
    Join Date
    May 2018
    Posts
    3

    Trying to write code to generate 1 record as a label - Error 3219

    Hi everyone,
    I am a complete novice when it comes to VBA so this is particularly challenging for me, I really hope you can help!

    I have created a database to be used as a visitor guestbook and fire register for our site. What I am trying to do is figure out a way where I can press a button and it generates a label for only 1 specified record which I can then modify and print as a visitor's pass.

    I have used this article from this site; https://www.techrepublic.com/article...access-record/ and I downloaded the accompanying sample file.
    I have copied and pasted the code directly from the sample file (amending relevant table names etc to my own) and after finding several errors which I seem to have rectified, I now have 1 final error which I cannot fathom.

    This is my code in full below but when I click the button in my form to test, I receive 2 errors: "-2147352573: Member not found" and then "Run-time error '3219': Operation not allowed in this context".

    Once clicked through the second error window, it highlights rst.Close in the errHandler at the very bottom in yellow. I'm at a complete loss as to what the problem is?

    Code:
    Option Compare Database
    Option Explicit
    
    Private Sub cmdPrintMultipleLabels_Click()
    'Print multiple labels for current record.
    
       Dim i As Integer
       Dim rst As ADODB.Recordset
       Set rst = New ADODB.Recordset
    
       'Delete previous label data.
       DoCmd.SetWarnings False
       DoCmd.RunSQL "DELETE FROM [Temporary_Contacts]"
       DoCmd.SetWarnings True
    
       On Error GoTo errHandler
    
       'Catch blank control.
       'If set to 0, label report is blank but runs.
       If IsNull(Me!txtNumberofLabels) Then
          MsgBox "Please indicate the number of labels you want to print", _
                 vbOKOnly, "Error"
          DoCmd.GoToControl "txtNumberOfLabels"
          Exit Sub
       End If
    
       rst.Open "[Temporary_Contacts]", CurrentProject.Connection, _
                adOpenDynamic, adLockPessimistic
    
       For i = 1 To Me!txtNumberofLabels.Value
          With rst
             .AddNew
             !Date = Me.Date
             !FirstName = Me.FirstName
             !LastName = Me.LastName
             !Company = Me.Company
             !HostsName = Me.HostsName
             !VehicleReg = Me.VehicleReg
             .Update
          End With
       Next i
    
       DoCmd.OpenReport "Single Visitor Pass", acViewPreview
    
       rst.Close
       Set rst = Nothing
    
       Exit Sub
    
    errHandler:
    
       MsgBox Err.Number & ": " & Err.Description, vbOKOnly, "Error"
       DoCmd.SetWarnings True
       rst.Close
       Set rst = Nothing
    
    End Sub


    Many thanks
    Kate
    Last edited by RuralGuy; 05-24-2018 at 07:09 AM. Reason: Added Format and Code Tags

  2. #2
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    Temporarily comment out the On Error... line and run the code. That should let you hit Debug on the first error and see where it is. From the sound of it, I'd guess a field name is spelled wrong.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  3. #3
    EBG is offline Novice
    Windows 7 64bit Access 2016
    Join Date
    May 2018
    Posts
    3

    Solved

    Quote Originally Posted by pbaldy View Post
    Temporarily comment out the On Error... line and run the code. That should let you hit Debug on the first error and see where it is. From the sound of it, I'd guess a field name is spelled wrong.
    Thanks Paul, I wasn't aware of the comment out function but as you stated, it highlighted a field name. When I checked the properties box for each name, this was different to what the actual column name was.

    Thanks for your help.

  4. #4
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    No problem Kate, and welcome to the site by the way!
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  5. #5
    ssanfu is offline Master of Nothing
    Windows 7 32bit Access 2010 32bit
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    Be aware that "DATE" is a reserved word in Access and shouldn't be used as an object name. Maybe use "VisPassDate" or "PassDate".....

    I know this is not a mission critical dB, but it is something to be aware of....

  6. #6
    EBG is offline Novice
    Windows 7 64bit Access 2016
    Join Date
    May 2018
    Posts
    3

    Solved

    Quote Originally Posted by ssanfu View Post
    Be aware that "DATE" is a reserved word in Access and shouldn't be used as an object name. Maybe use "VisPassDate" or "PassDate".....

    I know this is not a mission critical dB, but it is something to be aware of....
    Thanks Steve, I'll look into amending that. I know when I created the field a warning did pop up about this but I'll be honest I wasn't entirely sure what it meant.

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Insanity with Runtime Error 3219
    By sanderson in forum Programming
    Replies: 3
    Last Post: 10-30-2015, 07:10 AM
  2. Dcount of Query in VBA gives Error 3219
    By krausr79 in forum Access
    Replies: 2
    Last Post: 10-20-2014, 12:00 PM
  3. Replies: 2
    Last Post: 04-26-2012, 11:12 AM
  4. runtime error 3219
    By Rider570 in forum Programming
    Replies: 3
    Last Post: 07-07-2010, 09:12 PM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums