Input Box

  • Thread starter Thread starter Tom
  • Start date Start date
T

Tom

Advice on how to achieve the following would be
appreciated:

Am using an input box into which the user enters a
reference number.

After that number is entered I want to use Dcount or
DLookup to check if that number has previously been
entered into the table.

TIA

Tom
 
Dim strNum as String
strNum = InputBox("What number?")
If IsNumeric(strNum) Then
It Not IsNull(DLookup("MyID", "MyTable", "[MyID] = " & strNum)) Then
MsgBox "Already exists."
End If
Else
MsgBox "I said a number!"
End If
 
Thanks Allen

That does what I want.

If I want to expand this so that when

MsgBox "Already exists." appears the user is re-
prompted to enter a number, what is the best way to do
this?

TIA

Tom
-----Original Message-----
Dim strNum as String
strNum = InputBox("What number?")
If IsNumeric(strNum) Then
It Not IsNull(DLookup("MyID", "MyTable", "[MyID] = " & strNum)) Then
MsgBox "Already exists."
End If
Else
MsgBox "I said a number!"
End If

--
Allen Browne - Microsoft MVP. Perth, Western Australia.

Reply to group, rather than allenbrowne at mvps dot org.

Advice on how to achieve the following would be
appreciated:

Am using an input box into which the user enters a
reference number.

After that number is entered I want to use Dcount or
DLookup to check if that number has previously been
entered into the table.

TIA

Tom


.
 
Place the code inside a loop:

Dim bOk2GoOn as Boolean
Do While Not bOk2GoOn
'put your code in here.
'When the user gets things right:
bOk2GoOn = True
Loop

--
Allen Browne - Microsoft MVP. Perth, Western Australia.

Reply to group, rather than allenbrowne at mvps dot org.

Tom said:
Thanks Allen

That does what I want.

If I want to expand this so that when

MsgBox "Already exists." appears the user is re-
prompted to enter a number, what is the best way to do
this?

TIA

Tom
-----Original Message-----
Dim strNum as String
strNum = InputBox("What number?")
If IsNumeric(strNum) Then
It Not IsNull(DLookup("MyID", "MyTable", "[MyID] = " & strNum)) Then
MsgBox "Already exists."
End If
Else
MsgBox "I said a number!"
End If


Advice on how to achieve the following would be
appreciated:

Am using an input box into which the user enters a
reference number.

After that number is entered I want to use Dcount or
DLookup to check if that number has previously been
entered into the table.

TIA

Tom
 
Allen

If I understand correctly the code should be:

Dim strNum as String
Dim bOk2GoOn as Boolean
Do While Not bOk2GoOn

strNum = InputBox("What number?")
If IsNumeric(strNum) Then
If Not IsNull(DLookup("MyID", "MyTable", "[MyID] = "
& strNum)) Then
MsgBox "Already exists."



End If

If IsNull(DLookup("MyID", "MyTable", "[MyID] = "
& strNum)) Then

bOk2GoOn = True

EndIf

Loop

Else
MsgBox "I said a number!"
End If

Tom
-----Original Message-----
Place the code inside a loop:

Dim bOk2GoOn as Boolean
Do While Not bOk2GoOn
'put your code in here.
'When the user gets things right:
bOk2GoOn = True
Loop

--
Allen Browne - Microsoft MVP. Perth, Western Australia.

Reply to group, rather than allenbrowne at mvps dot org.

Thanks Allen

That does what I want.

If I want to expand this so that when

MsgBox "Already exists." appears the user is re-
prompted to enter a number, what is the best way to do
this?

TIA

Tom
-----Original Message-----
Dim strNum as String
strNum = InputBox("What number?")
If IsNumeric(strNum) Then
It Not IsNull(DLookup("MyID", "MyTable", "[MyID]
= "
& strNum)) Then
MsgBox "Already exists."
End If
Else
MsgBox "I said a number!"
End If


Advice on how to achieve the following would be
appreciated:

Am using an input box into which the user enters a
reference number.

After that number is entered I want to use Dcount or
DLookup to check if that number has previously been
entered into the table.

TIA

Tom


.
 
No. Much as I hate to contradict Allen, you don't even really need the
bOk2GoOn variable:

Dim strNum as String

Do While True
strNum = InputBox("What number?")
If IsNumeric(strNum) Then
If Not IsNull(DLookup("MyID", "MyTable", "[MyID] = " & strNum))
Then
MsgBox "Already exists."
Else
Exit Do
End If
Else
MsgBox "I said a number!"
End If
Loop

On the other hand, you might want to give them the ability to quit entering
numbers before they find a legitimate one:

Dim strNum as String

Dim bValidNumber as Boolean

Do While True
strNum = InputBox("What number?")
If Len(strNum) = 0 Then
Exit Do
Else
If IsNumeric(strNum) Then
If Not IsNull(DLookup("MyID", "MyTable", "[MyID] = " &
strNum)) Then
MsgBox "Already exists."
Else
bValidNumber = True
Exit Do
End If
Else
MsgBox "I said a number!"
End If
End If
Loop

Now, it they just hit enter, they can quit. bValidNumber will be true if
they entered a valid number, or False if they quit before they entered a
valid one.

--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)



Tom said:
Allen

If I understand correctly the code should be:

Dim strNum as String
Dim bOk2GoOn as Boolean
Do While Not bOk2GoOn

strNum = InputBox("What number?")
If IsNumeric(strNum) Then
If Not IsNull(DLookup("MyID", "MyTable", "[MyID] = "
& strNum)) Then
MsgBox "Already exists."



End If

If IsNull(DLookup("MyID", "MyTable", "[MyID] = "
& strNum)) Then

bOk2GoOn = True

EndIf

Loop

Else
MsgBox "I said a number!"
End If

Tom
-----Original Message-----
Place the code inside a loop:

Dim bOk2GoOn as Boolean
Do While Not bOk2GoOn
'put your code in here.
'When the user gets things right:
bOk2GoOn = True
Loop

--
Allen Browne - Microsoft MVP. Perth, Western Australia.

Reply to group, rather than allenbrowne at mvps dot org.

Thanks Allen

That does what I want.

If I want to expand this so that when

MsgBox "Already exists." appears the user is re-
prompted to enter a number, what is the best way to do
this?

TIA

Tom
-----Original Message-----
Dim strNum as String
strNum = InputBox("What number?")
If IsNumeric(strNum) Then
It Not IsNull(DLookup("MyID", "MyTable", "[MyID] = "
& strNum)) Then
MsgBox "Already exists."
End If
Else
MsgBox "I said a number!"
End If


message
Advice on how to achieve the following would be
appreciated:

Am using an input box into which the user enters a
reference number.

After that number is entered I want to use Dcount or
DLookup to check if that number has previously been
entered into the table.

TIA

Tom


.
 
Thanks Doug - that will do exactly what I want

Tom
-----Original Message-----
No. Much as I hate to contradict Allen, you don't even really need the
bOk2GoOn variable:

Dim strNum as String

Do While True
strNum = InputBox("What number?")
If IsNumeric(strNum) Then
If Not IsNull(DLookup
("MyID", "MyTable", "[MyID] = " & strNum))
Then
MsgBox "Already exists."
Else
Exit Do
End If
Else
MsgBox "I said a number!"
End If
Loop

On the other hand, you might want to give them the ability to quit entering
numbers before they find a legitimate one:

Dim strNum as String

Dim bValidNumber as Boolean

Do While True
strNum = InputBox("What number?")
If Len(strNum) = 0 Then
Exit Do
Else
If IsNumeric(strNum) Then
If Not IsNull(DLookup
("MyID", "MyTable", "[MyID] = " &
strNum)) Then
MsgBox "Already exists."
Else
bValidNumber = True
Exit Do
End If
Else
MsgBox "I said a number!"
End If
End If
Loop

Now, it they just hit enter, they can quit. bValidNumber will be true if
they entered a valid number, or False if they quit before they entered a
valid one.

--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)



Allen

If I understand correctly the code should be:

Dim strNum as String
Dim bOk2GoOn as Boolean
Do While Not bOk2GoOn

strNum = InputBox("What number?")
If IsNumeric(strNum) Then
If Not IsNull(DLookup("MyID", "MyTable", "[MyID] = "
& strNum)) Then
MsgBox "Already exists."



End If

If IsNull(DLookup("MyID", "MyTable", "[MyID] = "
& strNum)) Then

bOk2GoOn = True

EndIf

Loop

Else
MsgBox "I said a number!"
End If

Tom
-----Original Message-----
Place the code inside a loop:

Dim bOk2GoOn as Boolean
Do While Not bOk2GoOn
'put your code in here.
'When the user gets things right:
bOk2GoOn = True
Loop

--
Allen Browne - Microsoft MVP. Perth, Western Australia.
Tips for Access users - http://allenbrowne.com/tips.html
Reply to group, rather than allenbrowne at mvps dot org.

Thanks Allen

That does what I want.

If I want to expand this so that when

MsgBox "Already exists." appears the user is re-
prompted to enter a number, what is the best way to do
this?

TIA

Tom
-----Original Message-----
Dim strNum as String
strNum = InputBox("What number?")
If IsNumeric(strNum) Then
It Not IsNull(DLookup("MyID", "MyTable", "[MyID] = "
& strNum)) Then
MsgBox "Already exists."
End If
Else
MsgBox "I said a number!"
End If


message
Advice on how to achieve the following would be
appreciated:

Am using an input box into which the user enters a
reference number.

After that number is entered I want to use Dcount or
DLookup to check if that number has previously been
entered into the table.

TIA

Tom


.


.
 
Back
Top