View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
Mike H. Mike H. is offline
external usenet poster
 
Posts: 471
Default multiple updates to database

A couple questions:
1. If cow #1 has nothing in column C and you vaccinate for "Col-C Vaccine",
then you store the date in Column C. But if there is a date in that column
but it was "expired", then do you record the "Col-C Vaccine" in column C,
this time wiping out the old date that you replaced.

2. Do you always record a specific vaccine's date in a a specific column?
That is what it at first sounded like, but then later in your text, it led me
to believe that was not necessarily the case.

Based on your answers to these questions, this code might change a bit, but
this is the idea I have for doing this:

Sub DoForm()
Dim TheDate As Date
Dim X As Long
Dim NbrVaccined As Integer '
Dim Y As Integer

UserForm1.Show

If UserForm1.datefield = True Then
Let TheDate = UserForm1.datefield
Else
Exit Sub
End If

'get your cow #'s etc. Let's assume you assigned them to an array:
CowList(5,2) where the
'first element is the Cow #, the second # is the vaccine Type. Now you have
all the parts:

'just go to the list and write the data out:

Range("CowList").Select
X = ActiveCell.Row
Do While True
If Cells(X, 1).Value = Empty Then Exit Do 'if there is no cow # in col
A, then you're done.
For Y = 1 To NbrVaccined
If Cells(X, 1).Value = cowlist(Y, 1) Then
If cowlist(Y, 2) = 1 Then '(or whatever you use to differentiate
the type of vaccine)
Cells(X, 2).Value = TheDate
ElseIf cowlist(Y, 2) = 2 Then
Cells(X, 3).Value = TheDate
'etc....
End If
End If
Next
Loop



End Sub

HTH!