if 3*15

I

Irene Kral

Hello EB, i wonder if somebody could help me out with my problem.

I have got three fields in my form:
Input
ItemID
Pieces

The input field may just have the ItemID, or Pieces*ItemID

On Exit of Input I would like Access to check if the Input is just a number,
or if it has the quantity as well.

something like

if input is like number1*number2 then set Pieces=number1 and ItemID=number3
else Pieces=1 and ItemID=Input


how do i do that PLEASE?!?!?!?

thank you
 
K

Ken Snell \(MVP\)

Show us sample data that would be entered for both cases. What would be in
the Input textbox for both cases?
 
D

Dirk Goldgar

Irene Kral said:
Hello EB, i wonder if somebody could help me out with my problem.

I have got three fields in my form:
Input
ItemID
Pieces

The input field may just have the ItemID, or Pieces*ItemID

On Exit of Input I would like Access to check if the Input is just a
number, or if it has the quantity as well.

something like

if input is like number1*number2 then set Pieces=number1 and
ItemID=number3
else Pieces=1 and ItemID=Input


How about something like the following untested code for the Input field's
AfterUpdate event:

'----- start of untested sample code -----
Private Sub Input_AfterUpdate()

Dim astrParts() As String

With Me!Input
If Not IsNull(Me!Input) Then

astrParts = Split(.Value, "*")

Select Case UBound(astrParts)
Case 0
Me!Pieces = 1
Me!ItemID = astrParts(0)
Case 1
Me!Pieces = astrParts(0)
Me!ItemID = astrParts(1)
Case Else
MsgBox "That's not a valid entry! Please correct it."
End If

End With

End Sub
'----- end of untested sample code -----
 
I

Irene Kral

Dirk, you are a genious, untested but terrific, just one line missing (end
select)

I thank you SO much.

one last thing

is it possible to make another check, before parting the input field in 2
pieces?

lets say:

case one: Input = 45621

ItemId=45621
Pieces=1

case two: Input=2*45621
ItemID= 45621
Pieces=2

case three: Input=2/45621
ItemID=45621
Pieces=2/Quantity (another field in the table)

so, how do i make the check if / or * is the seperator?
 
D

Dirk Goldgar

Irene Kral said:
Dirk, you are a genious, untested but terrific, just one line missing (end
select)
Oops.

is it possible to make another check, before parting the input field in 2
pieces?

lets say:

case one: Input = 45621

ItemId=45621
Pieces=1

case two: Input=2*45621
ItemID= 45621
Pieces=2

case three: Input=2/45621
ItemID=45621
Pieces=2/Quantity (another field in the table)

so, how do i make the check if / or * is the seperator?

Hmm. You could do a second split after you've established that there's no
"*". Something like this:

'----- start of untested sample code -----
Private Sub Input_AfterUpdate()

Dim astrParts() As String
Dim strOperator As String

' Check for empty field.
If IsNull(Me!Input) Then
Exit Sub
End If

' Got something in the Input field.

With Me!Input

strOperator = "*"
astrParts = Split(.Value, strOperator)
If UBound(astrParts) = 0 Then
strOperator = "/"
astrParts = Split(.Value, strOperator)
End If
End With

Select Case UBound(astrParts)

Case 0
Me!Pieces = 1
Me!ItemID = astrParts(0)

Case 1
Me!ItemID = astrParts(1)

If strOperator = "*" Then
Me!Pieces = astrParts(0)
Else ' must be "/"
If Not IsNumeric(Me!Quantity) Then
MsgBox "Missing or invalid quantity."
Else
Me!Pieces = Clng(astrParts(0)) / Me!Quantity
End If
End If

Case Else
MsgBox "That's not a valid entry! Please correct it."

End Select

End Sub
'----- end of untested sample code -----

Note that I haven't put any error-handling code into the above. If the the
user's entry into Input contains non-numeric values other than the "*" or
"/" operator, errors will result. You probably want to examine both parts
of the entry to make sure they're valid.
 

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