L
Leanne
Hi, I have the following code in a form but do not know how to do the
following.
'copy the data to the database – this is the part I need to change.
When I copy the data to the database I want only the entry in CmbSiteList
updated with what is in the text box TxtDate.
IE when a user selects ‘Portsmouth’ the entry for Portsmouth on ‘Dates’ is
updated with data in TxtDate.
Column A contains the customers name (and this is growing)
Column B is for Invoice Date
Column C is for Visit Date
Please can someone help as the code I have so far I has been taken from
http://www.contextures.on.ca/xlUserForm01.html#SetUp and other sources and
has not been written by myself as I would not know how. I have included the
whole code for the form so that you can see exactly where I am at.
Private Sub SaveVisit_Click()
Dim iRow As Long
Dim ws As Worksheet
Dim foundCell As Range
Set ws = Worksheets("Dates")
With Worksheets(1).Range("A1:A65536")
Set foundCell = .Find(What:=CmbSiteList.Value, lookAt:=xlWhole, _
LookIn:=xlValues, SearchOrder:=xlRows, _
MatchCase:=True, MatchByte:=True)
If Not foundCell Is Nothing Then
foundCell.Offset(0, 2).Value = TxtDate.Value
End If
End With
'check all mandatory fields complete
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
Private Sub UserForm_Initialize()
CmbSiteList.RowSource = "Dates!A2:A300"
End Sub
following.
'copy the data to the database – this is the part I need to change.
When I copy the data to the database I want only the entry in CmbSiteList
updated with what is in the text box TxtDate.
IE when a user selects ‘Portsmouth’ the entry for Portsmouth on ‘Dates’ is
updated with data in TxtDate.
Column A contains the customers name (and this is growing)
Column B is for Invoice Date
Column C is for Visit Date
Please can someone help as the code I have so far I has been taken from
http://www.contextures.on.ca/xlUserForm01.html#SetUp and other sources and
has not been written by myself as I would not know how. I have included the
whole code for the form so that you can see exactly where I am at.
Private Sub SaveVisit_Click()
Dim iRow As Long
Dim ws As Worksheet
Dim foundCell As Range
Set ws = Worksheets("Dates")
With Worksheets(1).Range("A1:A65536")
Set foundCell = .Find(What:=CmbSiteList.Value, lookAt:=xlWhole, _
LookIn:=xlValues, SearchOrder:=xlRows, _
MatchCase:=True, MatchByte:=True)
If Not foundCell Is Nothing Then
foundCell.Offset(0, 2).Value = TxtDate.Value
End If
End With
'check all mandatory fields complete
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
Private Sub UserForm_Initialize()
CmbSiteList.RowSource = "Dates!A2:A300"
End Sub