Results 1 to 7 of 7
  1. #1
    akhlaq768 is offline Novice
    Windows 2K Access 2002
    Join Date
    Feb 2012
    Posts
    14

    Error on VB page, where do start?

    Hi,

    I'm desperately seeking your help on this one... my form has stopped working correctly, each time i populate the mandatory fields, and I then save the form, i get the following error message on the Visual Basic page

    Private Sub Form_AfterInsert()
    Me.txtFirstEntered = Date
    Me.txtEnteredBy = Environ("Username")
    If Me.txtLeadDivision = "Corporate" Or Me.txtLeadDivision = "Trust-wide" Or Me.txtLeadDivision = "Primary Care" Or Me.txtLeadDivision = "1" Or Me.txtLeadDivision = "2" Or Me.txtLeadDivision = "3" Or Me.txtLeadDivision = "4" Or Me.txtLeadDivision = "5" Or Me.txtLeadDivision = "A" Or Me.txtLeadDivision = "B" Or Me.txtLeadDivision = "C" Or Me.txtLeadDivision = "D" Then
    Me.txtNewProjectID = ("CA" & Me.txtLeadDivision & "-" & Format(Me.txtArbitraryNumber, "00000") & "-" & Right(Me.txtFirstEntered, 2))
    Else


    Me.txtNewProjectID = ("CA" & "0-" & Format(Me.txtArbitraryNumber, "00000") & "-" & Right(Me.txtFirstEntered, 2))
    End If
    MsgBox ("The code for the audit you just registered is " & Me.txtNewProjectID & ".")
    End Sub

    I think it may be something to do with txtArbitraryNumber but im not 100% sure or dont know where to start in fixing it

  2. #2
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows 7 64bit Access 2010 32bit
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,922
    Do you have Option Explicit at the top of your code page? What error message are you getting?

  3. #3
    akhlaq768 is offline Novice
    Windows 2K Access 2002
    Join Date
    Feb 2012
    Posts
    14
    yes i have an Option Explicit on top of the page and the error message i recieve says

    Compile error:
    Method or data member not found

  4. #4
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows 7 64bit Access 2010 32bit
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,922
    Which line is highlighted?

  5. #5
    akhlaq768 is offline Novice
    Windows 2K Access 2002
    Join Date
    Feb 2012
    Posts
    14
    ive inserted a screenshot of the error hope you can view it

    Click image for larger version. 

Name:	error.gif 
Views:	12 
Size:	5.8 KB 
ID:	9109

  6. #6
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows 7 64bit Access 2010 32bit
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,922
    I would start by *importing* everything into a fresh new db: http://www.btabdevelopment.com/ts/impnew

  7. #7
    Missinglinq's Avatar
    Missinglinq is offline VIP
    Windows 7 64bit Access 2007
    Join Date
    May 2012
    Location
    Richmond (Virginia, not North Yorkshire!)
    Posts
    3,018
    The error message is saying, in essence, that it cannot find a Control/Field named txtLeadDivision. If there is, in fact, one with that name, your Control named txtLeadDivision may be corrupt, or the Form, or the Database, itself. Importing everything into a new. blank file will resolve the latter two cases, but I'm not sure about the first case, where the Control is corrupt.

    If RG's advice doesn't work, you might Delete the txtLeadDivision Control and then re-create it.

    This has nothing to do with your problem (unless the txtLeadDivision Control doesn't exist) but when you have a large number of Ifs in an If...Then construct, or a lot of tests, like you do here

    Code:
    If Me.txtLeadDivision = "Corporate" Or Me.txtLeadDivision = "Trust-wide" Or Me.txtLeadDivision = "Primary Care" Or Me.txtLeadDivision = "1" Or Me.txtLeadDivision = "2" Or Me.txtLeadDivision = "3" Or Me.txtLeadDivision = "4" Or Me.txtLeadDivision = "5" Or Me.txtLeadDivision = "A" Or Me.txtLeadDivision = "B" Or Me.txtLeadDivision = "C" Or Me.txtLeadDivision = "D" Then
        Me.txtNewProjectID = ("CA" & Me.txtLeadDivision & "-" & Format(Me.txtArbitraryNumber, "00000") & "-" & Right(Me.txtFirstEntered, 2))
    Else
        Me.txtNewProjectID = ("CA" & "0-" & Format(Me.txtArbitraryNumber, "00000") & "-" & Right(Me.txtFirstEntered, 2))
    End If


    it's probably better to use a Select Case construct:

    Code:
    Select Case txtLeadDivision
    
    Case "Corporate", "Trust-wide", "Primary Care", "1", "2", "3", "4", "5", "A", "B", "C", "D"
      
      Me.txtNewProjectID = ("CA" & Me.txtLeadDivision & "-" & Format(Me.txtArbitraryNumber, "00000") & "-" & Right(Me.txtFirstEntered, 2))
    
    Case Else
      
      Me.txtNewProjectID = ("CA" & "0-" & Format(Me.txtArbitraryNumber, "00000") & "-" & Right(Me.txtFirstEntered, 2))
    
    End Select


    It's shorter/cleaner and much easier to read, as you'll see if you copy and paste it into the Form's code window.

    Linq ;0)>
    The problem with making anything foolproof...is that fools are so darn ingenious!

    All posts/responses based on Access 2003/2007

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

Similar Threads

  1. Page Header & Forced Page Break
    By Donnydon in forum Reports
    Replies: 1
    Last Post: 09-08-2011, 08:24 AM
  2. Error 3024 At Start UP
    By Damonpc in forum Access
    Replies: 10
    Last Post: 11-26-2010, 07:40 PM
  3. Page break on report inserts empty page between
    By Galadrielle in forum Reports
    Replies: 0
    Last Post: 07-07-2010, 04:18 AM
  4. Replies: 1
    Last Post: 05-22-2010, 08:30 PM
  5. where do i start with this error message?
    By Student4Life in forum Access
    Replies: 0
    Last Post: 01-09-2009, 04:12 PM

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