Command button to ask for a value

vidus

Confused User
Local time
Today, 14:56
Joined
Jun 21, 2009
Messages
117
Hello all,
I am trying to have a button ask for two values, and plug them both into the appropriate fields on the table. A msg box with both value boxes on it would be appropriate but so far I cant even get anything to show up.

So far I have the following, I am trying my best to get this to work but sadly, I am a noober... so any helpful hints would be helpful for me to learn!

Private Sub Command39_Click()

Value = InputBox("Enter a value for this job", "Value", Format(Me.Value, "Currency"))
If Len(Value) = 0 Then
iMsgResult = MsgBox("Can not accept Job without a value.", vbOKOnly, "Move failed")
GoTo success
End If

Job = InputBox("Enter the job number", "Job Number")
If Len(Job) = 0 Then
iMsgResult = MsgBox("You must enter a job number.", vbOKOnly, "Move failed")
GoTo success
End If

End Sub

Its coming up with errors all over the place. I know I have not defined success or failure, but I dont know what to do there. Any help?:confused:
 
Let's start with Value, which is not a good field name, as it will conflict with the Value property. If you can't change the field name, try:

Me.[Value]

Also, you seem to have GoTo success where I would expect failure, and you haven't defined where it's supposed to go.
 
Just noticed the last bit. You define it like so:

Success:
 
Let's start with Value, which is not a good field name, as it will conflict with the Value property. If you can't change the field name, try:

Me.[Value]

Also, you seem to have GoTo success where I would expect failure, and you haven't defined where it's supposed to go.

The value entered in the box is supposed to populate the "Value" field for that record... I dont know what goto success points to, ive just tried to use pieces of existing code in my db to make this work :o.
 
Alright this populates the fields, but only after a runtime error 424 "object required"..

Where did it go wrong?

Private Sub Command39_Click()

On Error GoTo errorHandler

Me.[Value] = InputBox("Enter a value for this job", "Value", Format(Me.Value, "Currency"))
If Len(Value) = 0 Then
iMsgResult = MsgBox("Can not accept Job without a value.", vbOKOnly, "Move failed")
GoTo success
End If

Me.[Job] = InputBox("Enter the job number", "Job Number")
If Len(Job) = 0 Then
iMsgResult = MsgBox("You must enter a job number.", vbOKOnly, "Move failed")
GoTo success
End If

errorHandler:
MsgBox Error$

wsp.Rollback

success:
wsp.CommitTrans

End Sub
 
I would just drop the GoTo lines; they aren't commonly used, other than for error handlers.

Normally you would just let the user enter values into textboxes on a form, then perform any validation or processing. If you want to do it with the button, you could do something like:

Code:
Variable = InputBox(...)
If Len(Variable) = 0 Then
  Msgbox...
Else
  Me.TextboxName = variable
End If
 
You're going to drop into the error handler no matter what. Here's an example of the common structuring of a sub with error handling:

http://www.baldyweb.com/ErrorTrap.htm

If you still have a problem, comment out the On Error line so you can see exactly what line is causing the error. I assume wsp has been defined elsewhere?
 
You're going to drop into the error handler no matter what. Here's an example of the common structuring of a sub with error handling:

http://www.baldyweb.com/ErrorTrap.htm

If you still have a problem, comment out the On Error line so you can see exactly what line is causing the error. I assume wsp has been defined elsewhere?

No wsp is not defined. Bear with me here, im new and confused. I get more errors if I delete the goto like you mentioned above, such as "expected ="
 
I may not have been clear; I meant the entire line:

GoTo success

You can leave it in if you want; it will work. Generally you can control program flow without using GoTo lines, except directing to or out of the exit/error handlers. Delete the wsp lines and post the entire code as it currently stands.
 
I may not have been clear; I meant the entire line:

GoTo success

You can leave it in if you want; it will work. Generally you can control program flow without using GoTo lines, except directing to or out of the exit/error handlers. Delete the wsp lines and post the entire code as it currently stands.

Here is the code as I have it. It still produces an error for object required.

Private Sub Command39_Click()

On Error GoTo errorHandler

Me.[Value] = InputBox("Enter a value for this job", "Value", Format(Me.Value, "Currency"))
If Len(Value) = 0 Then
iMsgResult = MsgBox("Can not accept Job without a value.", vbOKOnly, "Move failed")
GoTo success
End If

Me.[Job] = InputBox("Enter the job number", "Job Number")
If Len(Job) = 0 Then
iMsgResult = MsgBox("You must enter a job number.", vbOKOnly, "Move failed")
GoTo success
End If

Me.[Active] = True

errorHandler:
MsgBox Error$

wsp.Rollback

success:
end sub
 
Try this:

Code:
On Error GoTo errorHandler

Me.[Value] = InputBox("Enter a value for this job", "Value", Format(Me.[Value], "Currency"))
If Len(Me.[Value]) = 0 Then
  MsgBox("Can not accept Job without a value.", vbOKOnly, "Move failed")
  GoTo ExitHandler
End If

Me.[Job] = InputBox("Enter the job number", "Job Number")
If Len(Job) = 0 Then
  MsgBox("You must enter a job number.", vbOKOnly, "Move failed")
  GoTo ExitHandler
End If

Me.[Active] = True

ExitHandler:
  Exit Sub
errorHandler:
  MsgBox Err.Description
 
Try this:

Code:
On Error GoTo errorHandler

Me.[Value] = InputBox("Enter a value for this job", "Value", Format(Me.[Value], "Currency"))
If Len(Me.[Value]) = 0 Then
  MsgBox("Can not accept Job without a value.", vbOKOnly, "Move failed")
  GoTo ExitHandler
End If

Me.[Job] = InputBox("Enter the job number", "Job Number")
If Len(Job) = 0 Then
  MsgBox("You must enter a job number.", vbOKOnly, "Move failed")
  GoTo ExitHandler
End If

Me.[Active] = True

ExitHandler:
  Exit Sub
errorHandler:
  MsgBox Err.Description

almost.. still got a compile syntax error. but this works:

Private Sub Command39_Click()

On Error GoTo errorHandler

Me.[Value] = InputBox("Enter a value for this job", "Value", Format(Me.[Value], "Currency"))
If Len(Me.[Value]) = 0 Then
iMsgResult = MsgBox("Can not accept Job without a value.", vbOKOnly, "Move failed")
GoTo ExitHandler
End If

Me.[Job] = InputBox("Enter the job number", "Job Number")
If Len(Job) = 0 Then
iMsgResult = MsgBox("You must enter a job number.", vbOKOnly, "Move failed")
GoTo ExitHandler
End If

Me.[Active] = True

ExitHandler:
Exit Sub
errorHandler:
MsgBox Err.Description

i dont know what iMsgResult is, but it works... any idea what that does??
 
It's catching a return value from the message box, which you don't need in this situation. I suspect the parentheses are the problem. See if it works like this:

MsgBox "Can not accept Job without a value.", vbOKOnly, "Move failed"

Obviously since it works with the variable, you can leave it alone. It is an undeclared variable, which I don't like, but maybe this is one of those "one step at a time" situations. ;)
 
It's catching a return value from the message box, which you don't need in this situation. I suspect the parentheses are the problem. See if it works like this:

MsgBox "Can not accept Job without a value.", vbOKOnly, "Move failed"

Obviously since it works with the variable, you can leave it alone. It is an undeclared variable, which I don't like, but maybe this is one of those "one step at a time" situations. ;)

That did it. works better now too, before it kept returning to the first record after the function. now it stays on it.

Thank pbaldy!
 
No problemo, glad we got it sorted out.
 

Users who are viewing this thread

Back
Top Bottom