Help with Table Default Value

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I am building a library database, and this default value " Date Book was Borrowed + Day (21) " was working just fine (i think) , but I dont know what I did and whenever I try to place this default value in the "Ideal Date of Book Return" it gives a " 'mismatch' in the default value" when Im almost sure it worked in the past. What can I do to make the Ideal Date of Book Return be 3 weeks later than the date a book was borrowed. Its just so odd
 
I am building a library database, and this default value " Date Book was Borrowed + Day (21) " was working just fine (i think) , but I dont know what I did and whenever I try to place this default value in the "Ideal Date of Book Return" it gives a " 'mismatch' in the default value" when Im almost sure it worked in the past. What can I do to make the Ideal Date of Book Return be 3 weeks later than the date a book was borrowed. Its just so odd

A Table default value cannot reference another field in your table.
By putting

" Date Book was Borrowed + Day (21) "

in the Default property of a table field, you're trying to set the
date to THAT TEXT STRING - and " Date Book Was Borrowed + Day (21) "
is meaningful to a human reader, but not to a poor ignorant computer
program!

I would suggest that you need a little VBA code in the Form that
you're using to do the data entry. I presume you're comfortable with
using VBA code since you posted this message to the formscoding
newsgroup (if not post back for more details); just use the
AfterUpdate event of the [Date Book Was Borrowed] textbox with code
like

Private Sub Date_Book_Was_Borrowed_AfterUpdate()
If IsNull(Me!Ideal_Date_Of_Book_Return) Then
Me!Ideal_Date_Of_Book_Return = DateAdd("d", 21, _
Me!Date_Book_Was_Borrowed)
End If
End Sub

Just a suggestion: you'll find your code easier to read and maintain
if you use a naming convention and shorter fieldnames, without blanks
in them. You can always use Labels or the Caption property of fields
for human readability; but fieldnames like dtBorrowed and dtDue, bound
to textboxes txtdtBorrowed and txtdtDue, would make your code look
simpler.
 
Actually I have no idea how to do the code so I need clear steps. However the odd thing about this is that I got it working somehow in the past, and now it suddenly wont work. I dont know why.
 
Actually I have no idea how to do the code so I need clear steps. However the odd thing about this is that I got it working somehow in the past, and now it suddenly wont work. I dont know why.

Well, since I have no way of knowing what you are doing or where you
are doing it (YOU can see your database; I cannot!) I have no way of
knowing why it works or doesn't.

What I'm suggesting is that you open your Form in design view. Select
the control (textbox I presume, again - I CANNOT SEE YOUR DATABASE so
I'm not certain what type of control or what it's named) which I'm
guessing is named [Date Book Was Borrowed]. View its Properties. On
the Events tab find the After Update event and doubleclick the white
box by that event. The box will change to [Event Procedure] and the
VBA editor will open, with a Sub and an End Sub line. Replace those
two lines by copying and pasting this text.

Click Debug... Compile <your database> to compile this (and all) code.

Private Sub Date_Book_Was_Borrowed_AfterUpdate()
If IsNull(Me!Ideal_Date_Of_Book_Return) Then
Me!Ideal_Date_Of_Book_Return = DateAdd("d", 21, _
Me!Date_Book_Was_Borrowed)
End If
End Sub
 
Back
Top