PDA

View Full Version : کاربر جدید



sevigol
دوشنبه 22 تیر 1388, 13:29 عصر
سلام من می خوام کاربر جدید اضافه کنم کد هم گذاشتم ولی وقتی ذخیره رو میزنم کاری انجام نمیده خواهش میکنم کمکم کنید
2)می خوام این کاربر به جند تا جدول همزمان اضافه بشه با اکسس کار میکنم چیکار کنم

Adodc1.Recordset.MoveFirst
Do While Adodc1.Recordset.EOF = False
If Adodc1.Recordset.Fields("UserName") = Trim(Text2.Text) Then
MsgBox "پرسنلي بااين نام کاربري موجود است دوباره سعي کنيد ", vbYesNo, "پرسنل جديد"
Text2.Text = Empty
Text2.SetFocus
Exit Sub
End If
Adodc1.Recordset.MoveNext
Loop
'----------------
Adodc1.Recordset.AddNew
Adodc1.Recordset.Fields("UserName") = Trim(Text2.Text)
Adodc1.Recordset.Fields("Password") = Val(Text5.Text)
Adodc1.Recordset.Update
'--------
Text2.Text = ""
Text3.Text = ""
Text5.Text = ""
Text6.Text = ""
End Sub

HjSoft
دوشنبه 22 تیر 1388, 22:36 عصر
)می خوام این کاربر به جند تا جدول همزمان اضافه بشه با اکسس کار میکنم چیکار کنم
اين كه فقط به يك جدول اضافه ميشه ، در هر صورت من كد تصحيح شده رو براتون قرار مي دهم :
( البته اينو همين الان توي notepad نوشتم ، شمرنده اگه مشكل املايي داشت )

adodc1.recordset.refresh
adodc1.recordset.filter = "username = '" & trim(text2.text)
if adodc1.recordset.recordcount = 1 then
msgbox ("پرسنلي با اين نام كاربري موحود است ، لطفا نام كاربري ديگري انتخاب نماييد")
text2.text = ""
text2.setfocus
else
Adodc1.Recordset.AddNew
Adodc1.Recordset.Fields("UserName") = Trim(Text2.Text)
Adodc1.Recordset.Fields("Password") = Val(Text5.Text)
Adodc1.Recordset.Update
'--------
Text2.Text = ""
Text3.Text = ""
Text5.Text = ""
Text6.Text = ""
End if

ehsanocx
سه شنبه 23 تیر 1388, 11:27 صبح
دوست عزیز اینم کد کامل فرم تعریف کاربر جدید
توی دکمه ذخیره اینو بنویس

Private Sub CmdSave_Click()
On Error Resume Next
Adodc1.RecordSource = "Select user from login where user= '" + Trim(txtUserName.Text) + "'"
Adodc1.Refresh
If Adodc1.Recordset.RecordCount > 0 Then
MsgBox "äÇã ˜ÇÑÈÑí ʘÑÇÑí ÇÓÊ", vbCritical, "ÎØÇ"
txtUserName.Text = ""
txtUserName.SetFocus
Else
Adodc1.CommandType = adCmdTable
Adodc1.RecordSource = "login"
Adodc1.Refresh
If txtUserName.Text = "" Or txtPassword.Text = "" Or txtPassword1 = "" Then
txtUserName.SetFocus
b = MsgBox("áØÝÇ ÇØáÇÚÇÊ æÇÑÏ ˜äíÏ", vbCritical, "ÎØÇ")
End If
If txtPassword.Text <> txtPassword1.Text Then
MsgBox "˜áãå í ÚÈæÑåÇ ÈÇ åã ãØÇÈÞÊ äÏÇÑÏ", vbCritical, "ÎØÇ"
txtPassword.Text = Empty
txtPassword1.Text = Empty
txtPassword.SetFocus
End If
If txtUserName <> "" And txtPassword <> "" And txtPassword1 <> "" Then
Adodc1.Recordset.AddNew
Adodc1.Recordset.Fields("User") = txtUserName.Text
Adodc1.Recordset.Fields("Password") = txtPassword.Text
Adodc1.Recordset.Update
l = MsgBox("äÇã ˜ÇÑÈÑí ÌÏíÏ ÐÎíÑå ÔÏ", vbQuestion, "ÐÎííÑå")
Adodc1.Refresh
End If

End If

End Sub

توی فرم لود اینو بنویس

Private Sub Form_Load()
Adodc1.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & App.Path & "\Data.mdb"
Adodc1.CommandType = adCmdText
Adodc1.RecordSource = "Select * From Login"
Adodc1.Refresh
End Sub

توی textpassword دومیت که پسورد رو دوباره وارد می کنی توی رویداد lostfocus اینو بنویس.

Private Sub txtPassword1_LostFocus()
On Error Resume Next
If txtUserName.Text <> "" And txtPassword.Text <> txtPassword1.Text Then
MsgBox "˜áãå í ÚÈæÑåÇ ÈÇ åã ãØÇÈÞÊ äÏÇÑÏ", vbCritical, "ÎØÇ"
txtPassword.Text = Empty
txtPassword1.Text = Empty
txtPassword.SetFocus
End If
End Sub

اسم تکست باکستم اینو بزار
txtUserName
txtPassword
txtPassword1

موفق باشی. تشکر فراموش نشه