Home |
Search |
Today's Posts |
|
#1
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Hello,
I am currently working on a project in Word VBA. The userform that I have developed has a number of combo boxes which are populated from an Existing Excel Workbook. What I would like to have happen is when a user enters information into the combo box, the program searches the recordset and if the entry does not exist to add it automatically. I have asked this question in a few Word NG and have been subsequently directed to an Excel NG. Any assistance that could be provided would be greatly appreictaed. Z |
#2
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Z,
Set a reference to Excel from within your Word project (in the VBE) and use code like this, below. You really didn't explain a lot of the particulars, but this should get you going. HTH, Bernie MS Excel MVP Sub Macro1() Dim xlApp As Object Dim xlBook As Excel.Workbook Dim xlSht As Excel.Worksheet Dim xlCell As Excel.Range Dim myValue As String 'Redim to match your user-entered data type myValue = "Find me" 'Get this from your user's entered value in the combobox Set xlApp = CreateObject("excel.application") xlApp.Visible = True ' optional Set xlBook = xlApp.Workbooks.Open("C:\DeleteMe.xls") ' change to actual file name Set xlSht = xlBook.ActiveSheet Set xlCell = xlSht.Range("A:A").Find(myValue) ' set search range If xlCell Is Nothing Then ' add the value to the set at the bottom xlSht.Cells(xlSht.Rows.Count, 1).End(xlUp)(2).Value = myValue MsgBox "Added " & myValue & " to cell " & _ xlSht.Cells(xlSht.Rows.Count, 1).End(xlUp).Address(False, False, xlA1, True) xlBook.Save xlBook.Close Else MsgBox "Found " & myValue & " in cell " & xlCell.Address(False, False, xlA1, True) End If xlApp.Quit Set xlApp = Nothing End Sub "Zoltar54" wrote in message ... Hello, I am currently working on a project in Word VBA. The userform that I have developed has a number of combo boxes which are populated from an Existing Excel Workbook. What I would like to have happen is when a user enters information into the combo box, the program searches the recordset and if the entry does not exist to add it automatically. I have asked this question in a few Word NG and have been subsequently directed to an Excel NG. Any assistance that could be provided would be greatly appreictaed. Z |
#3
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Bernie,
Thnaks for the help so far, perhaps I could ask a few more questions? I have tried the code that you provided and it partially worked. As you mentioned I didn't provide enough particulars. What else can I provide to clrify the question? Z "Bernie Deitrick" wrote: Z, Set a reference to Excel from within your Word project (in the VBE) and use code like this, below. You really didn't explain a lot of the particulars, but this should get you going. HTH, Bernie MS Excel MVP Sub Macro1() Dim xlApp As Object Dim xlBook As Excel.Workbook Dim xlSht As Excel.Worksheet Dim xlCell As Excel.Range Dim myValue As String 'Redim to match your user-entered data type myValue = "Find me" 'Get this from your user's entered value in the combobox Set xlApp = CreateObject("excel.application") xlApp.Visible = True ' optional Set xlBook = xlApp.Workbooks.Open("C:\DeleteMe.xls") ' change to actual file name Set xlSht = xlBook.ActiveSheet Set xlCell = xlSht.Range("A:A").Find(myValue) ' set search range If xlCell Is Nothing Then ' add the value to the set at the bottom xlSht.Cells(xlSht.Rows.Count, 1).End(xlUp)(2).Value = myValue MsgBox "Added " & myValue & " to cell " & _ xlSht.Cells(xlSht.Rows.Count, 1).End(xlUp).Address(False, False, xlA1, True) xlBook.Save xlBook.Close Else MsgBox "Found " & myValue & " in cell " & xlCell.Address(False, False, xlA1, True) End If xlApp.Quit Set xlApp = Nothing End Sub "Zoltar54" wrote in message ... Hello, I am currently working on a project in Word VBA. The userform that I have developed has a number of combo boxes which are populated from an Existing Excel Workbook. What I would like to have happen is when a user enters information into the combo box, the program searches the recordset and if the entry does not exist to add it automatically. I have asked this question in a few Word NG and have been subsequently directed to an Excel NG. Any assistance that could be provided would be greatly appreictaed. Z |
#4
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Z,
I am currently working on a project in Word VBA. The userform that I have developed has a number of combo boxes How many? What naming scheme? What are they returning? How are they related to your database? which are populated from an Existing Excel Workbook. What I would like to have happen is when a user enters information into the combo box, the program searches the recordset and if the entry does not exist to add it automatically. Based on any value (combo-box), or a key value (primatry combo-box)? Add it to the end of the database? Where is the key value (Sheet name and column) and what data do you want to write to the database? HTH, Bernie MS Excel MVP "Zoltar54" wrote in message ... Bernie, Thnaks for the help so far, perhaps I could ask a few more questions? I have tried the code that you provided and it partially worked. As you mentioned I didn't provide enough particulars. What else can I provide to clrify the question? Z "Bernie Deitrick" wrote: Z, Set a reference to Excel from within your Word project (in the VBE) and use code like this, below. You really didn't explain a lot of the particulars, but this should get you going. HTH, Bernie MS Excel MVP Sub Macro1() Dim xlApp As Object Dim xlBook As Excel.Workbook Dim xlSht As Excel.Worksheet Dim xlCell As Excel.Range Dim myValue As String 'Redim to match your user-entered data type myValue = "Find me" 'Get this from your user's entered value in the combobox Set xlApp = CreateObject("excel.application") xlApp.Visible = True ' optional Set xlBook = xlApp.Workbooks.Open("C:\DeleteMe.xls") ' change to actual file name Set xlSht = xlBook.ActiveSheet Set xlCell = xlSht.Range("A:A").Find(myValue) ' set search range If xlCell Is Nothing Then ' add the value to the set at the bottom xlSht.Cells(xlSht.Rows.Count, 1).End(xlUp)(2).Value = myValue MsgBox "Added " & myValue & " to cell " & _ xlSht.Cells(xlSht.Rows.Count, 1).End(xlUp).Address(False, False, xlA1, True) xlBook.Save xlBook.Close Else MsgBox "Found " & myValue & " in cell " & xlCell.Address(False, False, xlA1, True) End If xlApp.Quit Set xlApp = Nothing End Sub "Zoltar54" wrote in message ... Hello, I am currently working on a project in Word VBA. The userform that I have developed has a number of combo boxes which are populated from an Existing Excel Workbook. What I would like to have happen is when a user enters information into the combo box, the program searches the recordset and if the entry does not exist to add it automatically. I have asked this question in a few Word NG and have been subsequently directed to an Excel NG. Any assistance that could be provided would be greatly appreictaed. Z |
#5
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Bernie,
I'm not sure if I follow you. To start, I have two combo boxes that I need to have update two seperate recordsets. The data consists of types of facilities ie warehouse, storefront, 3rd part vendor etc. Each combobox is loaded from a defined range in one excel workbook and are on the same sheet. As it stands now, there are some names listed in the recordsets however I need the source data (recordset) to be updated if and when a user enters a term that is not already on the list. For example warehouse is on the lost whereas Rail depot is not (and may need to be depending on the user preference). Does this clarify my needs further or did I make it worse. Z "Bernie Deitrick" wrote: Z, I am currently working on a project in Word VBA. The userform that I have developed has a number of combo boxes How many? What naming scheme? What are they returning? How are they related to your database? which are populated from an Existing Excel Workbook. What I would like to have happen is when a user enters information into the combo box, the program searches the recordset and if the entry does not exist to add it automatically. Based on any value (combo-box), or a key value (primatry combo-box)? Add it to the end of the database? Where is the key value (Sheet name and column) and what data do you want to write to the database? HTH, Bernie MS Excel MVP "Zoltar54" wrote in message ... Bernie, Thnaks for the help so far, perhaps I could ask a few more questions? I have tried the code that you provided and it partially worked. As you mentioned I didn't provide enough particulars. What else can I provide to clrify the question? Z "Bernie Deitrick" wrote: Z, Set a reference to Excel from within your Word project (in the VBE) and use code like this, below. You really didn't explain a lot of the particulars, but this should get you going. HTH, Bernie MS Excel MVP Sub Macro1() Dim xlApp As Object Dim xlBook As Excel.Workbook Dim xlSht As Excel.Worksheet Dim xlCell As Excel.Range Dim myValue As String 'Redim to match your user-entered data type myValue = "Find me" 'Get this from your user's entered value in the combobox Set xlApp = CreateObject("excel.application") xlApp.Visible = True ' optional Set xlBook = xlApp.Workbooks.Open("C:\DeleteMe.xls") ' change to actual file name Set xlSht = xlBook.ActiveSheet Set xlCell = xlSht.Range("A:A").Find(myValue) ' set search range If xlCell Is Nothing Then ' add the value to the set at the bottom xlSht.Cells(xlSht.Rows.Count, 1).End(xlUp)(2).Value = myValue MsgBox "Added " & myValue & " to cell " & _ xlSht.Cells(xlSht.Rows.Count, 1).End(xlUp).Address(False, False, xlA1, True) xlBook.Save xlBook.Close Else MsgBox "Found " & myValue & " in cell " & xlCell.Address(False, False, xlA1, True) End If xlApp.Quit Set xlApp = Nothing End Sub "Zoltar54" wrote in message ... Hello, I am currently working on a project in Word VBA. The userform that I have developed has a number of combo boxes which are populated from an Existing Excel Workbook. What I would like to have happen is when a user enters information into the combo box, the program searches the recordset and if the entry does not exist to add it automatically. I have asked this question in a few Word NG and have been subsequently directed to an Excel NG. Any assistance that could be provided would be greatly appreictaed. Z |
#6
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Z,
You would need to use three Finds to cover all three Comboboxes: myValue = ComboBox1.Value ' set search range for ComboBox1 Values Set xlCell = xlSht.Range("A:A").Find(myValue) If xlCell Is Nothing Then ' add the value to the set at the bottom xlSht.Cells(xlSht.Rows.Count, xlCell.Column).End(xlUp)(2).Value = myValue End If myValue = ComboBox2.Value ' set search range for ComboBox2 Values Set xlCell = xlSht.Range("C:C").Find(myValue) If xlCell Is Nothing Then ' add the value to the set at the bottom xlSht.Cells(xlSht.Rows.Count, xlCell.Column).End(xlUp)(2).Value = myValue End If myValue = ComboBox3.Value ' set search range for ComboBox3 Values Set xlCell = xlSht.Range("E:E").Find(myValue) If xlCell Is Nothing Then ' add the value to the set at the bottom xlSht.Cells(xlSht.Rows.Count, xlCell.Column).End(xlUp)(2).Value = myValue End If xlBook.Save xlBook.Close HTH, Bernie MS Excel MVP "Zoltar54" wrote in message ... Bernie, I'm not sure if I follow you. To start, I have two combo boxes that I need to have update two seperate recordsets. The data consists of types of facilities ie warehouse, storefront, 3rd part vendor etc. Each combobox is loaded from a defined range in one excel workbook and are on the same sheet. As it stands now, there are some names listed in the recordsets however I need the source data (recordset) to be updated if and when a user enters a term that is not already on the list. For example warehouse is on the lost whereas Rail depot is not (and may need to be depending on the user preference). Does this clarify my needs further or did I make it worse. Z "Bernie Deitrick" wrote: Z, I am currently working on a project in Word VBA. The userform that I have developed has a number of combo boxes How many? What naming scheme? What are they returning? How are they related to your database? which are populated from an Existing Excel Workbook. What I would like to have happen is when a user enters information into the combo box, the program searches the recordset and if the entry does not exist to add it automatically. Based on any value (combo-box), or a key value (primatry combo-box)? Add it to the end of the database? Where is the key value (Sheet name and column) and what data do you want to write to the database? HTH, Bernie MS Excel MVP "Zoltar54" wrote in message ... Bernie, Thnaks for the help so far, perhaps I could ask a few more questions? I have tried the code that you provided and it partially worked. As you mentioned I didn't provide enough particulars. What else can I provide to clrify the question? Z "Bernie Deitrick" wrote: Z, Set a reference to Excel from within your Word project (in the VBE) and use code like this, below. You really didn't explain a lot of the particulars, but this should get you going. HTH, Bernie MS Excel MVP Sub Macro1() Dim xlApp As Object Dim xlBook As Excel.Workbook Dim xlSht As Excel.Worksheet Dim xlCell As Excel.Range Dim myValue As String 'Redim to match your user-entered data type myValue = "Find me" 'Get this from your user's entered value in the combobox Set xlApp = CreateObject("excel.application") xlApp.Visible = True ' optional Set xlBook = xlApp.Workbooks.Open("C:\DeleteMe.xls") ' change to actual file name Set xlSht = xlBook.ActiveSheet Set xlCell = xlSht.Range("A:A").Find(myValue) ' set search range If xlCell Is Nothing Then ' add the value to the set at the bottom xlSht.Cells(xlSht.Rows.Count, 1).End(xlUp)(2).Value = myValue MsgBox "Added " & myValue & " to cell " & _ xlSht.Cells(xlSht.Rows.Count, 1).End(xlUp).Address(False, False, xlA1, True) xlBook.Save xlBook.Close Else MsgBox "Found " & myValue & " in cell " & xlCell.Address(False, False, xlA1, True) End If xlApp.Quit Set xlApp = Nothing End Sub "Zoltar54" wrote in message ... Hello, I am currently working on a project in Word VBA. The userform that I have developed has a number of combo boxes which are populated from an Existing Excel Workbook. What I would like to have happen is when a user enters information into the combo box, the program searches the recordset and if the entry does not exist to add it automatically. I have asked this question in a few Word NG and have been subsequently directed to an Excel NG. Any assistance that could be provided would be greatly appreictaed. Z |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
controling a .xls from another .xls | New Users to Excel | |||
Excel User Form using 2 Combo Box with 1st Combon controling the 2 | Excel Programming | |||
Controling Acrobat PDFs | Excel Programming | |||
CheckBox controling a ComboBox | Excel Programming |