method or data member not found on click (1 Viewer)

helmerr

Registered User
Joined
Nov 27, 2013
Messages
140
Hi everyone,

I have a form and some code that I copied from another form (because I wanted to keep the same layout) and altered one of the private subs for a button's click event. When I click the button on the newly copied and edited form, I get the error as follows:

Method or data member not found. It then highlights the top line "Private Sub btnAdd_Click." Can I get some assistance please?

Code:
Private Sub btnAdd_Click()
'
Dim db As Database
Dim rec As Recordset

Set db = CurrentDb
Set rec = db.OpenRecordset("Select * from tblOdometer")

'test required fields
If IsNull(Me.txtrmbDate) _
        Or IsNull(Me.txtrmbTimeIn) _
        Or IsNull(Me.cbormbTSASup1.Value) _
        Or IsNull(Me.cbormbLEO0400_0600.Value) Then
    
    MsgBox "Please fill in all required fields."
Else

'add records to able
rec.AddNew
rec("rmbDate") = Me.txtrmbDate
rec("rmbTimeIn") = Me.txtrmbTimeIn
rec("rmbTSASup1") = Me.rmbTSASup1
rec("rmbLEO0400-0600") = Me.rmbLEO0400_0600
rec("rmbLEO0600-1800") = Me.rmbLEO0600_1800
rec("rmbLEO1800-0100") = Me.rmbLEO1800_0100
rec("rmbTimeOut") = Me.rmbTimeOut
rec("rmbTSASup2") = Me.rmbTSASup2
'rec("rmbTotalTSAHrs") = Me.rmbTotalTSAHrs


rec.Update

Set rec = Nothing
Set db = Nothing

MsgBox "Record saved."

'Requery form
Me.Requery

' Clear All Controls
    Me.txtrmbDate = Null
    Me.txtrmbTimeIn = Null
    Me.cbormbTSASup1.Value = Null
    Me.cbormbLEO0400_0600.Value = Null
    Me.cbormbLE0600_1800.Value = Null
    Me.cbormbLEO1800_0100.Value = Null
    Me.rmbTimeOut = Null
    Me.cbormbTSASup2.Value = Null
    Me.rmbTotalTSAHrs = Null
End If
'
End Sub
Please let me know if you need more info. Thanks
 

Minty

AWF VIP
Joined
Jul 26, 2013
Messages
6,539
Copy your code minus the sub names then delete the whole thing. Go back to your form and create a new OnClick event procedure. Paste your code back in. Access keeps track of event procedures in dark and mysterious way and the Voodoo gets upset when you mess with it.
 

helmerr

Registered User
Joined
Nov 27, 2013
Messages
140
Hmm. Ok, i copied and then deleted everything. Access then prompted me to use the macro or code builder this time, and I pasted the content (minus the subs) back but I still get the same error :-(
 

Galaxiom

Super Moderator
Staff member
Joined
Jan 20, 2009
Messages
11,828
Could be a corrupted form.

Select all the objects on the form. Copy and paste them to a new form.

Copy and paste all the code to the new form's module. (You can create the module by adding an event to one object.) Go though and add Event Procedure to each object that has a Sub. Usually they link up again just fine.
 

helmerr

Registered User
Joined
Nov 27, 2013
Messages
140
Thanks everyone. Neither of those actually worked (but could have played a part in the fix). I'm really not sure what did it. I ended up creating a new blank form and pasting in from the old, and pasting in the code for each sub. When that didn't work, I commented out each line and got down to the "me.requery" and it gave a different error. At least I was past the previous. At any rate, its working properly. Thanks again
 

Users Who Are Viewing This Thread (Users: 0, Guests: 1)

Top Bottom