Code

fixious123

Registered User.
Local time
Today, 17:41
Joined
Oct 3, 2002
Messages
49
What would be the correct code for this. Basically Im building a shot record database and have a Combo box that contains 3 different types of shots and when selected the DateAdd function calculates a due date. I hope this will reset for each record or be able to change for each individual. Any help greatly appreciated..

Private Sub Combo109_Change()
If Combo109 = "Typh-Vi" Then
Text86 = DateAdd("yyyy", 2, [Typhoid Taken])
If Combo109 = "Oral Typh" Then
Text86 = DateAdd("yyyy", 5, [Typhoid Taken])
If Combo109 = "Typh B" Then
Text86 = DateAdd("yyyy", 3, [Typhoid Taken])
End If
End Sub
 
Try this:
Code:
Private Sub Combo109_Change()
If Combo109 = "Typh-Vi" Then
  Text86 = DateAdd("yyyy", 2, [Typhoid Taken])
ElseIf Combo109 = "Oral Typh" Then
  Text86 = DateAdd("yyyy", 5, [Typhoid Taken])
Else Combo109 = "Typh B" Then
  Text86 = DateAdd("yyyy", 3, [Typhoid Taken])
End If
End Sub

If you wish to store the value in Text86, make sure it's a bound field. The Combo109 should not be a bound field.
 
Text86 is bound to???? And that code gives me an error. Is there suppossed to be an ElseIf in the 6th line. Thanks
 
Combo

Also, sorry the combo box works as far as updating the box with the correct dates but it doesn't save that information between each record. When I open up the database the combo box is blank and the date reverts back to the "taken" date. How do I save the date and selection for each individual record. Thanks
 
Fixious,

DCX's code looks good...

A "bound form" is connected to a table (or two). A "bound control" is connected to a field in a table. Make a change to the data in a textbox on a form that's bound to a table, and that change is sent to the corresponding field and record in the table, which is saved on disk, which means the data is still there next time you visit it via a form.

How can you tell if a form is bound to a table? Look in the form's Record Source property. If there is a valid table or query name there, the form is bound to a table (or two).

How can you bind a form to a table? Create the form using the form wizard -- it walks you through the steps. Or type a valid table or query name in the form's Record Source property in the Property Dialog.

How can you tell whether a control (such as a textbox) on a form is bound to a field in a table? Look at the control's Control Source property in the control's Property Dialog --- you will see a valid field name there if everything's A-OK.

Regards,
Tim
 
Date Add problem

The combo box is working, it calculates the dates based on the date taken that I type in but when I reopen the form the selection in the combo box disappears and is blank. The date stays the same for each individual record. Im using the date add function to calculate the date.
 
Fixious,

Click the combo box when your form is in Design View. If you
don't see a property dialog on your screen, doube-click the combo until a property dialog box appears. In this dialog box, on the All tab, is there anything in the combo's Control Source property (which is second from the top, below Name)? A field name?

If not, type in the appropriate field name. If there is no field name in your table to hold this info, make a brief detour to add a ShotType field to your table and then fill in the combo's control source property.

If it still doesn't work, give yourself a shot and try again.

Regards,
Tim
 

Users who are viewing this thread

Back
Top Bottom