|
|
|||||||||
|
|||||||||
|
|||||||||
| |
|||
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
two unbound box
i have created a form like
firstname ______ Last name _______ Add this record >>[command button with pic of arrow] edit this record >>[command button with pic of arrow] these two text boxes are not bounded to any table they are two text boxes What i want is when the user type in the first name and the last name and presses the add this record, my form (candidate profile form) should show up with this name typed in (the name which i just typed) and when the user presses the edit this record... the command button (arrow) should search for the record in the database and if no record exists, itshow record not found and if it finds any records which resembles the the same candidate profile form should show the appropraite record of the person i have typed in first name and the last name. |
|
#2
|
|||
|
|||
|
For the command button Add:
Dim strFirstName As String, strLastName As String Dim stDocName As String stDocName = "candidate profile form" If Not IsNull(txtFirstName) Then strFirstName = txtFirstName.Value End If If Not IsNull(txtLastName) Then strLastName = txtLastName.Value End If DoCmd.OpenForm stDocName, , , , acFormAdd Forms![candidate profile form]![FirstName].Value = strFirstName Forms![candidate profile form]![LastName].Value = strLastName For the command button Edit: Dim db As DAO.Database Dim rs As DAO.Recordset Dim strSql As String Dim strFirstName As String, strLastName As String Dim stDocName As String Dim i As Integer stDocName = "candidate profile form" If Not IsNull(txtFirstName) Then strFirstName = txtFirstName.Value End If If Not IsNull(txtLastName) Then strLastName = txtLastName.Value End If Set db = CurrentDb() strSql = "SELECT NameOfTable.ID, NameOfTable.FirstName, NameOfTable.LastName " & _ "FROM NameOfTable " & _ "WHERE [NameOfTable].FirstName = '" & strFirstName & "'" & _ " AND [NameOfTable].LastName ='" & strLastName & "'" Set rs = db.OpenRecordset(strSql, dbOpenSnapshot) If rs.RecordCount <> 0 Then With rs i = rs!ID End With DoCmd.OpenForm stDocName, , , "[ID]= " & i Else strSql = "SELECT NameOfTable.ID, NameOfTable.FirstName, NameOfTable.LastName " & _ "FROM NameOfTable " & _ "WHERE [NameOfTable].FirstName Like'" & strFirstName & "*" & "'" Set rs = db.OpenRecordset(strSql, dbOpenSnapshot) If rs.RecordCount <> 0 Then DoCmd.OpenForm stDocName, , , "[FirstName]Like'" & strFirstName & "*" & "'" Else strSql = "SELECT NameOfTable.ID, NameOfTable.FirstName, NameOfTable.LastName " & _ "FROM NameOfTable " & _ "WHERE [NameOfTable].LastName Like'" & strLastName & "*" & "'" Set rs = db.OpenRecordset(strSql, dbOpenSnapshot) If rs.RecordCount <> 0 Then DoCmd.OpenForm stDocName, , , "[LastName]Like'" & strLastName & "*" & "'" Else MsgBox "There Are No Records That Match " & _ vbCrLf & vbTab & strFirstName & " " & strLastName End If End If End If db.Close lwells |
![]() |
| Viewing: Dev Articles Community Forums > Databases > Microsoft Access Development > two unbound box |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|