4 Replies - 3698 Views - Last Post: 07 April 2013 - 07:14 PM Rate Topic: -----

#1 random_guru  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 01-April 13

creating a login form with MS access. forms are crashing

Posted 01 April 2013 - 03:49 AM

i am using .mdb file as database and i have created a new command-button type using user control , the form is crashing as soon as i execute them.the database name and table name are same (login1)

here is the code for the first form:
Dim a As String
Dim b As String
Public Sub conne()
dbase
End Sub
Private Sub Form_Load()
a = ""
b = ""
conne
MsgBox "Total Number of records = " & rs.RecordCount
If (rs.EOF = True) Then
rs.MovePrevious
End If
rs.MoveFirst
End Sub

Private Sub xpcmdbutton1_Click()
 If (Text1.Text <> "" And Text2.Text <> "") Then
 Do While Not rs.EOF
 a = rs.Fields(1).Value
 b = rs.Fields(2).Value
 If a = (Text1.Text) Then
     Text2.SetFocus
      End If
 If b = (Text2.Text) Then
        MsgBox "hello"
            End If
 Loop
 End If
 MsgBox "sorry"
End Sub


here is code for the function which i used to connect with database . this code is stored separate module
Public db As New ADODB.Connection
Public rs As New ADODB.Recordset
Public bol As Boolean

Public Sub dbase()
Set db = New ADODB.Connection
db.CursorLocation = adUseClient
  db.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=E:\cool time\ooad\ooad_profiles\login1.mdb;Persist Security Info=False"
   rs.Open "Select * from login1", db, 3, 3
  End Sub



yes, i have searched for the solutions, but nobody offered a solution for crashing of forms??

Is This A Good Question/Topic? 0
  • +

Replies To: creating a login form with MS access. forms are crashing

#2 maj3091  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 301
  • View blog
  • Posts: 1,782
  • Joined: 26-March 09

Re: creating a login form with MS access. forms are crashing

Posted 01 April 2013 - 06:33 AM

Do you get any error messages?

Can you be more specific in what it does when "crashing" (i.e.: does the form hang, does it just close the app).

Is it crashing on form load or when you click this "new" button that you refer to in your description - any more information you can give may help people solve your issue.

Might be worth adding some error handling into your functions...always good practice.
Was This Post Helpful? 0
  • +
  • -

#3 random_guru  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 01-April 13

Re: creating a login form with MS access. forms are crashing

Posted 01 April 2013 - 07:55 AM

NO error messages so far

the form simply hangs, when i click the button [xpcmdbutton1_Click()]
Was This Post Helpful? 0
  • +
  • -

#4 maj3091  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 301
  • View blog
  • Posts: 1,782
  • Joined: 26-March 09

Re: creating a login form with MS access. forms are crashing

Posted 01 April 2013 - 08:05 AM

You need to add a MoveNext into your loop....you don't seem to increment the record in that loop.

Private Sub xpcmdbutton1_Click()
 If (Text1.Text <> "" And Text2.Text <> "") Then
 Do While Not rs.EOF
 a = rs.Fields(1).Value
 b = rs.Fields(2).Value
 If a = (Text1.Text) Then
     Text2.SetFocus
      End If
 If b = (Text2.Text) Then
        MsgBox "hello"
            End If
 Loop
 End If
 MsgBox "sorry"
End Sub


If you tried debugging your code, you would see that it's stuck in the loop.

This post has been edited by maj3091: 01 April 2013 - 08:19 AM

Was This Post Helpful? 1
  • +
  • -

#5 BobRodes  Icon User is offline

  • Your Friendly Local Curmudgeon
  • member icon

Reputation: 574
  • View blog
  • Posts: 2,989
  • Joined: 19-May 09

Re: creating a login form with MS access. forms are crashing

Posted 07 April 2013 - 07:14 PM

Try running your code and hitting Ctrl-break. You'll see what maj means. Since you never move to the next record, you never get to the end of the file. By the way, I do this all the time. But I fix it, because I'm an expert. :)

p. s. your "conne" sub doesn't perform any real function, because all it does is call another function. Removing it and calling db directly would be a simplification.

This post has been edited by BobRodes: 07 April 2013 - 07:16 PM

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1