![]() |
Insert record into Excel database using a custom VBA form?
Rank Newbie here.
I've initialized a database area in a worksheet, and using Edit-Define, called the area "database", and am trying to code a custom form in VBA to insert the data from the form to the database. I want to add a new record at the bottom of the database list. I don't know how to code this, or find help on it. I've done lots of this in SQL but never in VBA to an Excel database/list. Can I have some sample code for this? PS. I don't want to use an automatic form (Data-Forms) because a "current date" field is in the database and I want to generate it automatically for the user. |
Insert record into Excel database using a custom VBA form?
This assumes that the UF has a text box into which the new entry is typed
named "TextBox1" and that there is a command button named "CommandButton1". This command button is clicked to add the new entry to the end of the db. The db is assumed to be in column A of "Sheet1" and all cells below the db in column A are empty. Therefore, the cell identity for the new entry is determined by finding the last entry in column A and offsetting 1 cell down. Note that the named range is therefore unnecessary. Paste the following to the UF code module: Dim c As Range Private Sub UserForm_Activate() GetNewEntryAddress End Sub Private Sub CommandButton1_Click() c.Value = TextBox1.Text GetNewEntryAddress End Sub Private Sub GetNewEntryAddress() Dim ws As Worksheet Set ws = Sheets("Sheet1") Set c = ws.Cells(Rows.Count, 1).End(xlUp)(2) End Sub " wrote: Rank Newbie here. I've initialized a database area in a worksheet, and using Edit-Define, called the area "database", and am trying to code a custom form in VBA to insert the data from the form to the database. I want to add a new record at the bottom of the database list. I don't know how to code this, or find help on it. I've done lots of this in SQL but never in VBA to an Excel database/list. Can I have some sample code for this? PS. I don't want to use an automatic form (Data-Forms) because a "current date" field is in the database and I want to generate it automatically for the user. |
Insert record into Excel database using a custom VBA form?
|
Insert record into Excel database using a custom VBA form?
thanks, guys!
I'll try out the code. Nice to have people respond this way. |
All times are GMT +1. The time now is 01:22 PM. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com