Adding a new record to table (1 Viewer)

Winterwolf73

New member
Local time
Today, 07:47
Joined
Jul 3, 2020
Messages
26
Ok everyone. I am going to apologize now. I am extremely new to VBA coding. I have gotten to the point of banging my head off a brick wall. I found this bit of code that I think will work to get to my end goal. I have a number of unbound user defined text boxes. Here is what I am trying to do.

1. I have a form which has tabbed pages added to it. The first page is a customer look up (which works fine because it is using a query with the "Like" criteria in place.
2. The second tab is for added a new customer to the table. Below is the code I have in place on the button to add the record.

Code Tags Added by UG
Please use Code Tags when posting VBA Code

Please read this for further information:-
https://www.access-programmers.co.u...e-use-code-tags-when-posting-vba-code.240420/
Please feel free to Remove this Comment

Code:
     Private Sub NewCustomer_Click()
     Dim tblCustomers As DAO.Recordset

     Set tblCustomers = CurrentDb.OpenRecordset("SELECT * FROM [Customer Table]")
     tblCustomers.AddNew
     tblCustomers![Last Name] = Me.Label5
     tblCustomers![First Name] = Me.Label7
     ' tblCustomers![Account Number] = Me.AccountNumber
     ' tblCustomers![Project] = Me.Project
     ' tblCustomers![Project Total] = Me.ProjectTotal
     ' tblCustomers![Address] = Me.Address
     ' tblCustomers![City] = Me.City
     ' tblCustomers![State] = Me.State
     ' tblCustomers![Zip] = Me.ZipCode
     ' tblCustomers![Phone Number] = Me.PhoneNumber
     ' tblCustomers![Email Address] = Me.EmailAddress
     tblCustomers.Update
     tblCustomers.Close
     Set tblCustomers = Nothing
     DoCmd.Close
     End Sub

Originally, instead of "Me.Label5" it was "Me.Label5.Value". However, every time I attempted to test it i received a "Method or Data Member not found" error. So I did some more research. I decided to take out the .Value to see if that was the problem. Now I get a Run-Time 438 error.

Any assistance you can give would be GREATLY appreciated.
 
Last edited by a moderator:

theDBguy

I’m here to help
Staff member
Local time
Today, 05:47
Joined
Oct 29, 2018
Messages
21,357
Hi. Welcome to AWF!

Are you sure it's a label? Normally, it would be a Textbox.
 

jdraw

Super Moderator
Staff member
Local time
Today, 08:47
Joined
Jan 23, 2006
Messages
15,361
Further to theDBGuy's comment, you said I have a number of unbound user defined text boxes.
I think you are dealing with text boxes, not labels.
 

MajP

You've got your good things, and you've got mine.
Local time
Today, 08:47
Joined
May 21, 2018
Messages
8,463
"Me.Label5.Value". However, every time I attempted to test it i received a "Method or Data Member not found"
Based on this error, I assume it is a label since a label does not have a value property. It has a caption property.
me.Label5.caption
 

Winterwolf73

New member
Local time
Today, 07:47
Joined
Jul 3, 2020
Messages
26
Thank you all. Evidently, my logic did not match what the computer needed. It works now.
 

theDBguy

I’m here to help
Staff member
Local time
Today, 05:47
Joined
Oct 29, 2018
Messages
21,357
Thank you all. Evidently, my logic did not match what the computer needed. It works now.
Hi. Congratulations! Glad to hear you got it sorted out. Good luck with your project.
 

Pat Hartman

Super Moderator
Staff member
Local time
Today, 08:47
Joined
Feb 19, 2002
Messages
42,970
If you use bound forms, you don't have to run queries. You appear to be doing work that you don't need to do.
 

Winterwolf73

New member
Local time
Today, 07:47
Joined
Jul 3, 2020
Messages
26
Pat I had thought about that, but I don't want to accidentally replace information... I have done that before.
 

Users who are viewing this thread

Top Bottom