InputBox - Is this correct?

  • Thread starter Thread starter Tcs
  • Start date Start date
T

Tcs

I have a particular db (Access 2k) which I link via ODBC to DB2 on our AS/400.
Currently, the code I created always runs every time I open my db. This code
deletes all the ODBC links and recreates them from a table of library and table
names of the tables to which I create my links. At the time I created my code
(almost 2 years ago) I thought that I *had* to re-establish my links every time
I opened my db.

I've just added a bit of code to give me an option. At the beginning of my
function, I've added:

strInput = "N"
strInput = InputBox("Do you want to restablish the ODBC links?...(Y/N)")
If strInput = "N" Then Exit Function

This *does* seem to work. But I don't know if it's good programming practice.
(I've done little to nothing with either input from the keyboard like this, or
forms. So I just don't know.)

Is this "OK"? If not, how *should* I do it? Any advice?

I appreciate the feedback, thanks in advance,

Tom
 
I have a particular db (Access 2k) which I link via ODBC to DB2 on our AS/400.
Currently, the code I created always runs every time I open my db. This code
deletes all the ODBC links and recreates them from a table of library and table
names of the tables to which I create my links. At the time I created my code
(almost 2 years ago) I thought that I *had* to re-establish my links every time
I opened my db.

I've just added a bit of code to give me an option. At the beginning of my
function, I've added:

strInput = "N"
strInput = InputBox("Do you want to restablish the ODBC links?...(Y/N)")
If strInput = "N" Then Exit Function

This *does* seem to work. But I don't know if it's good programming practice.
(I've done little to nothing with either input from the keyboard like this, or
forms. So I just don't know.)

Is this "OK"? If not, how *should* I do it? Any advice?

I appreciate the feedback, thanks in advance,

Tom

Why a function. A function returns a value. You're not returning a
value here.

Sub WhatToDo()
If InputBox("Do you want to restablish the ODBC links?...(Y/N)","What
do you want to do?","N") = "N" Then
Else
' Do any other response here
End If
End Sub

Entering an "N" or just clicking OK without entering, and nothing will
happen.
 
I wonder why the OP is not using the MsgBox function for this?

If Msgbox("Re-establish the ODBC Links?", vbYesNo<> vbYes Then
Exit function
End if

Using the input function leaves a lot of leeway. If the user click Ok or
Cancel without entering anything, the posted code will not exit since
strInput will be a zero-length string. If the user enters "No", then the
code will not exit. "No" is not equal to "N"
 
If you do try it, please fix my typo. I seem to have left out a closing parentheses.

If Msgbox("Re-establish the ODBC Links?", vbYesNo) <> vbYes Then
 
Back
Top