Required Amount

S

Stockwell43

Hello,

I have an auction database that I built for the March of Dimes(with the help
of many people from this forum and thank you for that). It works fine except
for one thing, how can I set it up to except a minimum bid? In otherwords, If
the starting price is $5.00 a person HAS to bid in increments of say .50 or
$1.00. Is there a way to do this? I have it set up now where they have to put
in an amount and not "0" or blank. Here is the code I currently have in the
field.

Private Sub NewBid_AfterUpdate()
If Not IsNull(Me.NewBid) And Me.NewBid > 0 Then
Me.CurrentPrice = Me.CurrentPrice + Me.NewBid
End If
End Sub

Private Sub NewBid_Exit(Cancel As Integer)
If IsNull(Me.NewBid <= 0) Or Me.NewBid <= 0 Then
Cancel = True
MsgBox "Value is required!", vbOKOnly
Me.NewBid.SetFocus
If Me.NewBid <= 0 Then
Me.NewBid = Null
End If
If varCurrentPrice > 0 Then 'there was a value in this control
Me.NewBid = varCurrentPrice
End If
End If

End Sub

Any help would be greatly appreciated!!

Thanks!!!
 
D

Dirk Goldgar

Stockwell43 said:
Hello,

I have an auction database that I built for the March of Dimes(with the
help
of many people from this forum and thank you for that). It works fine
except
for one thing, how can I set it up to except a minimum bid? In otherwords,
If
the starting price is $5.00 a person HAS to bid in increments of say .50
or
$1.00. Is there a way to do this? I have it set up now where they have to
put
in an amount and not "0" or blank. Here is the code I currently have in
the
field.

Private Sub NewBid_AfterUpdate()
If Not IsNull(Me.NewBid) And Me.NewBid > 0 Then
Me.CurrentPrice = Me.CurrentPrice + Me.NewBid
End If
End Sub

Private Sub NewBid_Exit(Cancel As Integer)
If IsNull(Me.NewBid <= 0) Or Me.NewBid <= 0 Then
Cancel = True
MsgBox "Value is required!", vbOKOnly
Me.NewBid.SetFocus
If Me.NewBid <= 0 Then
Me.NewBid = Null
End If
If varCurrentPrice > 0 Then 'there was a value in this control
Me.NewBid = varCurrentPrice
End If
End If

End Sub

Any help would be greatly appreciated!!


I'd suggest that you not use the Exit event for validating the user's entry.
Use the BeforeUpdate event instead -- that's what it's for.

I'm not sure of all the criteria you want to place on the new bid. I think
you want to make sure that it's not null and is greater than the current
price. If I understand your message correctly, you also want to force it to
be incremental by a certain amount, so it must be a multiple of 50 cents, or
a dollar. Lets suppose that it's 50 cents. Then you might have a
BeforeUpdate event procedure like this:

'----- start of untested air code -----
Private Sub NewBid_BeforeUpdate(Cancel As Integer)

Const conBidIncrement = .50

With Me.NewBid
If IsNull(.Value) Then
Cancel = True
MsgBox "Value is required!"
ElseIf .Value <= Nz(Me.CurrentPrice, 0) Then
Cancel = True
MsgBox "Bid must be greater than current price!"
ElseIf (Fix(.Value/ conBidIncrement) * conBidIncrement) = .Value _
Then
Cancel = True
MsgBox "Bid must be in increments of " & conBidIncrement & "!"
End If
End With

End Sub
'----- end of code -----
 
S

Stockwell43

Hi Dirk, thank you for your response.

It doesn't seem to work correctly to the database. Let me clarify further.
Your code is specifiying that the new bid (increment) must be higher than
current amount. I may have frased it incorrectly in my first email. The New
Bid field(Ichanged the name on the form) is actually what I want to be the
increased amount. So if Current price is $15.00, if someone wants to bid they
enter the additional amount they are willing to pay. So if they are willing
to pay $17.00 they input $2.00 and when they click enter bid, it adds that
amount to the current price. I just don't want anyone bidding less than .50
or a $1.00 because it might go $15.01, $15.02 people are strange like that.
So that is why I want to force a minimum increment to be added to the current
price. Does that make sense?
 
D

Dirk Goldgar

Stockwell43 said:
Hi Dirk, thank you for your response.

It doesn't seem to work correctly to the database. Let me clarify further.
Your code is specifiying that the new bid (increment) must be higher than
current amount. I may have frased it incorrectly in my first email. The
New
Bid field(Ichanged the name on the form) is actually what I want to be the
increased amount. So if Current price is $15.00, if someone wants to bid
they
enter the additional amount they are willing to pay. So if they are
willing
to pay $17.00 they input $2.00 and when they click enter bid, it adds that
amount to the current price. I just don't want anyone bidding less than
.50
or a $1.00 because it might go $15.01, $15.02 people are strange like
that.
So that is why I want to force a minimum increment to be added to the
current
price. Does that make sense?

Oh, I see. I didn't understand that the "new bid" is actually an increment
over the current amount, even though I should have seen that from your
AfterUpdate event. It's not clear to me now, though, whether you want every
bid to be in increments of .50 -- that is, it must be evenly divisible by
..50, so that a bid of .75 would not be acceptable -- or whether you just
want .50 to be the minimum bid.

For the former case -- bid increments of .50 -- modify the code to be like
this:

'----- start of code for bid increments -----
Private Sub NewBid_BeforeUpdate(Cancel As Integer)

Const conBidIncrement = .50

With Me.NewBid
If IsNull(.Value) Then
Cancel = True
MsgBox "Value is required!"
ElseIf .Value <= 0) Then
Cancel = True
MsgBox "Bid must be a positive amount!"
ElseIf (Fix(.Value/ conBidIncrement) * conBidIncrement) = .Value _
Then
Cancel = True
MsgBox "Bid must be in increments of " & conBidIncrement & "!"
End If
End With

End Sub
'----- end of code for bid increments -----

For the latter case -- a simple minimum bid -- modify the code to be like
this:

'----- start of code for minimum bid -----
Private Sub NewBid_BeforeUpdate(Cancel As Integer)

Const conMinimumBid = .50

With Me.NewBid
If IsNull(.Value) Then
Cancel = True
MsgBox "Value is required!"
ElseIf .Value < conMinimumBid) Then
Cancel = True
MsgBox "Bid must at least " & conMinimumBid & "!"
End If
End With

End Sub
'----- end of code for minimum bid -----
 
S

Stockwell43

Thanks Dirk,

My original thought was each bid increase has to be a minimum of .50 not
necessarily in crements of .50. I probably didn't explain that right, I
apologize. However, I would like to try both to see which way works best.
Thank you for the thinking ahead.

I popped in the code and both pieces get stuck on this:

MsgBox "Value is required!"
ElseIf .Value < conMinimumBid) Then

The ElseIf line is red.
 
D

Dirk Goldgar

Stockwell43 said:
I popped in the code and both pieces get stuck on this:

MsgBox "Value is required!"
ElseIf .Value < conMinimumBid) Then

The ElseIf line is red.


Sorry, that's a copy/paste/fail-to-fix error. It should have been:

ElseIf .Value < conMinimumBid Then
 
S

Stockwell43

That did it Dirk, it works like a charm!!!

Thank you once again for your, as always it is most appreciated!

One question: If I ever want to change the minimum all I would have to do is
replace the .5 to 1.00 or 2.00 correct?
 
D

Dirk Goldgar

Stockwell43 said:
That did it Dirk, it works like a charm!!!

Thank you once again for your, as always it is most appreciated!

One question: If I ever want to change the minimum all I would have to do
is
replace the .5 to 1.00 or 2.00 correct?


Correct. I put that in there as a constant, so you have to change the code
to modify it, but the change is simple and only has to be made in one place.
You could move that constant declaration to some other module, to put it
together with other constants if you like, or you could put it in a table
and look it up from there when you need it. But that's all more complicated
than I think you want at the moment.
 
S

Stockwell43

I just tried and works great and is easy to change. Thanks again to you and
everyone who helped me get this thing up to par. All of you folks make this
site worth it's weight in gold to people like myself who depend on it often
for help or just general questions. I think I speak for everyone when I say
your contributions to this site an others does not go unappreciated!

Thanks again!
 

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