error code

coley

Coley
Local time
Today, 23:19
Joined
Feb 22, 2005
Messages
39
Hi

I have an DB with a few input boxes, if the user enters a answer that is not in the correct format, i.e. a date, I get an error message, what code do I put in so when the incorrect format is entered, the user is informed and gets the opportunity to enter the details again?

Cheers

Coley
 
You could do many things... you could loop until it is entered correctly.. you could do an onerror event that brings up an input box... you could make a function that checks the format before it is recorded.

The sky's the limit

-modest
 
Use the Form OnError event to trap the error number
 
Modest said:
you could loop until it is entered correctly.. you could do an onerror event that brings up an input box
Rich said:
Use the Form OnError event to trap the error number

Haha, Rich are you reading my posts :D
 
Try this

Using the like operator
' For Dates
tryagain:
ans = InputBox("Please enter a date")
If Not IsDate(ans) then
MsgBox("Invalid Date format!")
Goto tryagain
End If

' For Text
tryagain:
ans = InputBox("Please enter some text")
If Not ans Like "text format" then
MsgBox("Invalid text format!")
Goto tryagain
End If


You get the idea. I normally don't use spaghetti code, but this one works for me... :)
 
If I did something like this, I would loop instead of using goto.
The thing is labels/goto is just bad practice and NASTY

Code:
do while not isdate(ans) or ans = ""
    ans = InputBox("Please enter a date")
    If Not IsDate(ans) Then MsgBox("Invalid Date format!")
loop
 
Spaghetti, ... :)

Your talking to an old Apple programmer - sometimes it's hard to get that spaghetti code out of my system, even though I know it's a bad practice! The loop, of course, is the better choice.
 
I'm Italian and I dont like spaghetti ---- blasphemy :)
 
cheers for the help, the loop works fine but now the text entered into the input box (when in the correct format) does not populate into the desired field, how can I incorporate this into the loop code?
 
where's the desired field and what type of object is it?
 
its a text box

the code i am using that populates the user input to the text box is:

Private Sub Command2_Click()
txtdate = InputBox("Please enter a date")
End Sub
 
Code:
Dim ans As String

Do While Not ans like "computer*" or ans = ""
    ans = InputBox("Please enter a date")
    If Not ans like "computer*" Then MsgBox("Invalid Text format!")
Loop

Me.textboxName.Value = ans
 
Last edited:
there's plenty already listed in this forum... just do a search at the top for it.
 

Users who are viewing this thread

Back
Top Bottom