Wrox Home  
Search P2P Archive for: Go

  Return to Index  

access thread: Assigning values entered into a dialogbox to an abject variable


Message #1 by "Sander Groffen" <sander.groffen@z...> on Thu, 30 Aug 2001 13:12:01
Hello, 



I am just beginning to learn Access programming, so forgive me if the 

following question is very basic.



I am using Access 2000 version 9.0 to write a database application. My 

main procedure is located in a module and I am using ADO commands to 

connect to a back-end database. This works fine, but now I want to open a 

dialog box (or form) to enter multiple variables. The entered values 

should be assigned directly to 2 fields of an object declared in the 

module. Is it possible to do this without defining a special table with 

only one record and two fields?



To make things clear I pasted the source code below. Best regards,

Sander Groffen



----------------------------------------------------------------------

Public Sub Inloggen()



'called from the Sub Main()

'uses the following global variables:

'cnObj

'rsObj

'strServerPath

'strUsername



Dim strUser As String

Dim strPass As String

Dim strFilter As String

Dim frmInLoggen As New Form_frmLogin

Dim Done As Boolean



'Initialise variables

Set cnObj = New ADODB.Connection

Set rsObj = New ADODB.Recordset

strFilter = "SELECT Name,Password FROM Users;"

Done = False



'Open the table "users" from the back-end server

cnObj.Open strServerPath

rsObj.Open "SELECT Name,Password FROM Users", cnObj, adUseClient, 

adLockReadOnly



While Not Done

    'Enter the username and password; this dialog should be improved!

    strUser = Trim(InputBox("User:", "Enter username"))

    strPass = Trim(InputBox("Password:", "Enter password"))

    

    'Check if the values occur together in the table "users"

    rsObj.MoveFirst

    While Not rsObj.EOF

        If (strUser = rsObj("Name")) And (strPass = rsObj("Password")) Then

            strUsername = strUser

            Done = True

            rsObj.MoveLast  'ends the while-loop after login confirmation

        End If

        rsObj.MoveNext

    Wend

    If booIngelogd = False Then MsgBox "Try again.", vbOKOnly, "Failed"

    Debug.Print "Ingelogd: " & booIngelogd

Wend



'Close the Database and Recordset object

rsObj.Close

cnObj.Close

Set rsObj = Nothing

Set cnObj = Nothing



End Sub

Message #2 by "abed edammat" <edammat@y...> on Thu, 30 Aug 2001 13:45:10
> Hello, 

> 

> I am just beginning to learn Access programming, so forgive me if the 

> following question is very basic.

> 

> I am using Access 2000 version 9.0 to write a database application. My 

> main procedure is located in a module and I am using ADO commands to 

> connect to a back-end database. This works fine, but now I want to open 

a 

> dialog box (or form) to enter multiple variables. The entered values 

> should be assigned directly to 2 fields of an object declared in the 

> module. Is it possible to do this without defining a special table with 

> only one record and two fields?

> 

> To make things clear I pasted the source code below. Best regards,

> Sander Groffen

> 







hi sander 



 i think that you have to create  a form with two unbounded controls 

and thrught you are entring the values there must be acode in the form 

environment  create a dinamic recordset to keep the values and send it to 

the moudle as a parameters



bye..

> ----------------------------------------------------------------------

> Public Sub Inloggen()

> 

> 'called from the Sub Main()

> 'uses the following global variables:

> 'cnObj

> 'rsObj

> 'strServerPath

> 'strUsername

> 

> Dim strUser As String

> Dim strPass As String

> Dim strFilter As String

> Dim frmInLoggen As New Form_frmLogin

> Dim Done As Boolean

> 

> 'Initialise variables

> Set cnObj = New ADODB.Connection

> Set rsObj = New ADODB.Recordset

> strFilter = "SELECT Name,Password FROM Users;"

> Done = False

> 

> 'Open the table "users" from the back-end server

> cnObj.Open strServerPath

> rsObj.Open "SELECT Name,Password FROM Users", cnObj, adUseClient, 

> adLockReadOnly

> 

> While Not Done

>     'Enter the username and password; this dialog should be improved!

>     strUser = Trim(InputBox("User:", "Enter username"))

>     strPass = Trim(InputBox("Password:", "Enter password"))

>     

>     'Check if the values occur together in the table "users"

>     rsObj.MoveFirst

>     While Not rsObj.EOF

>         If (strUser = rsObj("Name")) And (strPass = rsObj("Password")) 

Then

>             strUsername = strUser

>             Done = True

>             rsObj.MoveLast  'ends the while-loop after login confirmation

>         End If

>         rsObj.MoveNext

>     Wend

>     If booIngelogd = False Then MsgBox "Try again.", vbOKOnly, "Failed"

>     Debug.Print "Ingelogd: " & booIngelogd

> Wend

> 

> 'Close the Database and Recordset object

> rsObj.Close

> cnObj.Close

> Set rsObj = Nothing

> Set cnObj = Nothing

> 

> End Sub

Message #3 by "Yehuda Rosenblum" <Yehuda@I...> on Thu, 30 Aug 2001 08:54:26 -0400
Sounds like you want a SQL update statement.  You can either use the Ado

Update or execute an update statement.  To do this just set the field

values equal to what you want and then do a recordset update.

Alternatively, you can use the sql Update statement and a ado connection

Execute Command (UPDATE table_name SET colum_name =3D value, colum_name 

=3D

value WHERE etc. (the where clause is optional to limit the statement).



-----Original Message-----

From: Sander Groffen [mailto:sander.groffen@z...]

Sent: Thursday, August 30, 2001 9:12 AM

To: Access

Subject: [access] Assigning values entered into a dialogbox to an abject

variable





Hello,



I am just beginning to learn Access programming, so forgive me if the

following question is very basic.



I am using Access 2000 version 9.0 to write a database application. My

main procedure is located in a module and I am using ADO commands to

connect to a back-end database. This works fine, but now I want to open

a

dialog box (or form) to enter multiple variables. The entered values

should be assigned directly to 2 fields of an object declared in the

module. Is it possible to do this without defining a special table with

only one record and two fields?



To make things clear I pasted the source code below. Best regards,

Sander Groffen



----------------------------------------------------------------------

Public Sub Inloggen()



'called from the Sub Main()

'uses the following global variables:

'cnObj

'rsObj

'strServerPath

'strUsername



Dim strUser As String

Dim strPass As String

Dim strFilter As String

Dim frmInLoggen As New Form_frmLogin

Dim Done As Boolean



'Initialise variables

Set cnObj =3D New ADODB.Connection

Set rsObj =3D New ADODB.Recordset

strFilter =3D "SELECT Name,Password FROM Users;"

Done =3D False



'Open the table "users" from the back-end server

cnObj.Open strServerPath

rsObj.Open "SELECT Name,Password FROM Users", cnObj, adUseClient,

adLockReadOnly



While Not Done

    'Enter the username and password; this dialog should be improved!

    strUser =3D Trim(InputBox("User:", "Enter username"))

    strPass =3D Trim(InputBox("Password:", "Enter password"))

   

    'Check if the values occur together in the table "users"

    rsObj.MoveFirst

    While Not rsObj.EOF

        If (strUser =3D rsObj("Name")) And (strPass =3D 

rsObj("Password"))

Then

            strUsername =3D strUser

            Done =3D True

            rsObj.MoveLast  'ends the while-loop after login

confirmation

        End If

        rsObj.MoveNext

    Wend

    If booIngelogd =3D False Then MsgBox "Try again.", vbOKOnly, 

"Failed"

    Debug.Print "Ingelogd: " & booIngelogd

Wend



'Close the Database and Recordset object

rsObj.Close

cnObj.Close

Set rsObj =3D Nothing

Set cnObj =3D Nothing



End Sub

Message #4 by "Pardee, Roy E" <roy.e.pardee@l...> on Thu, 30 Aug 2001 07:34:51 -0700
Judging from your code, it looks like what you really want to do is validate

a username and password (read from InputBox() commands) against the records

in a table in your database.



If that's right, you're probably best off incorporating the user-supplied

variables into a WHERE clause in your SQL statement, use that statement to

pull a recordset out of the back-end, and then checking to see whether it

contains any records.  So for instance you might change your Open statement

to something like



rsObj.Open "SELECT Name,Password FROM Users " _

           "WHERE Name = '" & Trim(InputBox("User:", "Enter username")) &

"'" _

           "AND Password = '" & Trim(InputBox("Password:", "Enter

password")) & "'" _

		, cnObj, adUseClient, 



And then use code like so to test whether the username and password are

recognized.



If rsOjb.EOF And rsObj.BOF Then

	' No such combo of username and password in the table--login

unsuccessful

Else

	' user validated--proceed

End If





Hope that helps...



-Roy



P.S. Unsolicited extra advice: reconsider the field name "Name"--it's a

reserved keyword in VB & may cause hard-to-find bugs later on.



-----Original Message-----

From: Sander Groffen [mailto:sander.groffen@z...]

Sent: Thursday, August 30, 2001 6:12 AM

To: Access

Subject: [access] Assigning values entered into a dialogbox to an abject

variable





Hello, 



I am just beginning to learn Access programming, so forgive me if the 

following question is very basic.



I am using Access 2000 version 9.0 to write a database application. My 

main procedure is located in a module and I am using ADO commands to 

connect to a back-end database. This works fine, but now I want to open a 

dialog box (or form) to enter multiple variables. The entered values 

should be assigned directly to 2 fields of an object declared in the 

module. Is it possible to do this without defining a special table with 

only one record and two fields?



To make things clear I pasted the source code below. Best regards,

Sander Groffen



----------------------------------------------------------------------

Public Sub Inloggen()



'called from the Sub Main()

'uses the following global variables:

'cnObj

'rsObj

'strServerPath

'strUsername



Dim strUser As String

Dim strPass As String

Dim strFilter As String

Dim frmInLoggen As New Form_frmLogin

Dim Done As Boolean



'Initialise variables

Set cnObj = New ADODB.Connection

Set rsObj = New ADODB.Recordset

strFilter = "SELECT Name,Password FROM Users;"

Done = False



'Open the table "users" from the back-end server

cnObj.Open strServerPath

rsObj.Open "SELECT Name,Password FROM Users", cnObj, adUseClient, 

adLockReadOnly



While Not Done

    'Enter the username and password; this dialog should be improved!

    strUser = Trim(InputBox("User:", "Enter username"))

    strPass = Trim(InputBox("Password:", "Enter password"))

    

    'Check if the values occur together in the table "users"

    rsObj.MoveFirst

    While Not rsObj.EOF

        If (strUser = rsObj("Name")) And (strPass = rsObj("Password")) Then

            strUsername = strUser

            Done = True

            rsObj.MoveLast  'ends the while-loop after login confirmation

        End If

        rsObj.MoveNext

    Wend

    If booIngelogd = False Then MsgBox "Try again.", vbOKOnly, "Failed"

    Debug.Print "Ingelogd: " & booIngelogd

Wend



'Close the Database and Recordset object

rsObj.Close

cnObj.Close

Set rsObj = Nothing

Set cnObj = Nothing



End Sub


  Return to Index