Help please - real beginner at form code

L

Leanne

Hi, I have the following code in a form but do not know how to do the
following with it.
1. The CmbSiteList is a combo box and I do not know how to generate the
options as there are many and chaning. This would contain a list of company
names that is ever growing. These company names are on the sheet 'Dates' but
are determined by another sheet which is the master list. Entries in the
'Dates' sheet calculate new data for the master list also.

2. When I copy the data to the database I want only the entry in CmbSiteList
updated with what is in the text box TxtDate.

Please can someone help as the code I have so far I have taken from
http://www.contextures.on.ca/xlUserForm01.html#SetUp and have not written
myself as I would not know how.

Private Sub SaveVisit_Click()
Dim iRow As Long
Dim ws As Worksheet
Set ws = Worksheets("Dates")

'find first empty row in database
iRow = ws.Cells(Rows.Count, 1) _
.End(xlUp).Offset(1, 0).Row

'check for a part number
If Trim(Me.TxtDate.Value) = "" Then
Me.TxtDate.SetFocus
MsgBox "Please enter a valid Date"
Exit Sub
End If
If Trim(Me.CmbSiteList.Value) = "" Then
Me.CmbSiteList.SetFocus
MsgBox "Please select a Site"
Exit Sub
End If

'copy the data to the database
ws.Cells(iRow, 1).Value = Me.CmbSiteList.Value
ws.Cells(iRow, 2).Value = Me.TxtDate.Value

'clear the data
Me.CmbSiteList.Value = ""
Me.TxtDate.Value = ""
Me.CmbSiteList.SetFocus

End Sub
Private Sub CloseVisit_Click()
Unload Me
End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top