L
Little Penny
I have a table of Laptop Computers (tbl_Laopts) that has a foreign key (UserID) with is link to the user info table(tbl_UserInfo) primarykey (UserID).
I created a form for Laptop table and on that form so that I can show user assigned if any I created 6 combo boxes that are bound to the UserID Field
by way of query. In this form the User ID is column 0. it works great.
MY Code:
Private Sub Form_Current()
Me.cboFName.Value = Me.UserID.Column(1)
Me.cboLName.Value = Me.UserID.Column(2)
Me.cboDept.Value = Me.UserID.Column(3)
Me.cboEXT.Value = Me.UserID.Column(4)
Me.cboCellPhone.Value = Me.UserID.Column(5)
Me.cboEmail.Value = Me.UserID.Column(6)
End Sub
Private Sub Form_Open(Cancel As Integer)
Me.cboFName.Value = Me.UserID.Column(1)
Me.cboLName.Value = Me.UserID.Column(2)
Me.cboDept.Value = Me.UserID.Column(3)
Me.cboEXT.Value = Me.UserID.Column(4)
Me.cboCellPhone.Value = Me.UserID.Column(5)
Me.cboEmail.Value = Me.UserID.Column(6)
End Sub
Private Sub UserID_AfterUpdate()
Me.cboFName.Value = Me.UserID.Column(1)
Me.cboLName.Value = Me.UserID.Column(2)
Me.cboDept.Value = Me.UserID.Column(3)
Me.cboEXT.Value = Me.UserID.Column(4)
Me.cboCellPhone.Value = Me.UserID.Column(5)
Me.cboEmail.Value = Me.UserID.Column(6)
End Sub
Works Great........
So I then decided for ease of use to do it the for the computers table but with a twist I rearranged the columns so the when you click on the arrow of
the UserID field, it shows you the list but the last name is first followed by the first name and than the UserID which I believe to now be column 2.
I also rearranged the query to match the columns, but it does not work. In the properties of the UserID form field I changed the bound colum to 2. But
if I change it to 1 the user ID show up in the right field but none of the other info.
Here is my new code
Private Sub cboLocationID_NotInList(NewData As String, Response As Integer)
On Error GoTo cboLocationID_NotInList_Err
Dim intAnswer As Integer
Dim strSQL As String
intAnswer = MsgBox("The Loaction ID " & Chr(34) & NewData & _
Chr(34) & " is not currently in loaction list." & vbCrLf & _
"Would you like to add the new LoactionID to the list now?" _
, vbQuestion + vbYesNo, "Location ID")
If intAnswer = vbYes Then
strSQL = "INSERT INTO tbl_Location([LocationID]) " & _
"VALUES ('" & NewData & "');"
DoCmd.SetWarnings False
DoCmd.RunSQL strSQL
DoCmd.SetWarnings True
MsgBox "The new location has been added to the list." _
, vbInformation, "Location ID"
Response = acDataErrAdded
Else
MsgBox "Please choose a Location ID from the list." _
, vbInformation, "LocationID"
Response = acDataErrContinue
Me.cboLocationID.Undo
End If
cboLocationID_NotInList_Exit:
Exit Sub
cboLocationID_NotInList_Err:
MsgBox Err.Description, vbCritical, "Error"
Resume cboLocationID_NotInList_Exit
End Sub
Private Sub cmdNewUser_Click()
DoCmd.OpenForm "frm_UserSearch_Dialog", acNormal
End Sub
Private Sub Form_BeforeUpdate(Cancel As Integer)
If Not Me.NewRecord Then
If MsgBox("Changes have been made to this record" _
& vbCrLf & "Do you want to save these changes?" _
, vbYesNo + vbDefaultButton2, "Changes Made...") = vbYes Then
DoCmd.RunCommand acCmdSaveRecord
Else
Cancel = True
Me.Undo
Me.cboLName.Value = Me.UserID.Column(0)
Me.cboFName.Value = Me.UserID.Column(1)
Me.cboDept.Value = Me.UserID.Column(3)
Me.cboEXT.Value = Me.UserID.Column(4)
Me.cboCellPhone.Value = Me.UserID.Column(5)
Me.cboEmail.Value = Me.UserID.Column(6)
End If
End If
End Sub
Private Sub Form_Current()
Me.cboLName.Value = Me.UserID.Column(0)
Me.cboFName.Value = Me.UserID.Column(1)
Me.cboDept.Value = Me.UserID.Column(3)
Me.cboEXT.Value = Me.UserID.Column(4)
Me.cboCellPhone.Value = Me.UserID.Column(5)
Me.cboEmail.Value = Me.UserID.Column(6)
End Sub
Private Sub Form_Open(Cancel As Integer)
Me.cboLName.Value = Me.UserID.Column(0)
Me.cboFName.Value = Me.UserID.Column(1)
Me.cboDept.Value = Me.UserID.Column(3)
Me.cboEXT.Value = Me.UserID.Column(4)
Me.cboCellPhone.Value = Me.UserID.Column(5)
Me.cboEmail.Value = Me.UserID.Column(6)
End Sub
Private Sub UserID_AfterUpdate()
Me.cboLName.Value = Me.UserID.Column(0)
Me.cboFName.Value = Me.UserID.Column(1)
Me.cboDept.Value = Me.UserID.Column(3)
Me.cboEXT.Value = Me.UserID.Column(4)
Me.cboCellPhone.Value = Me.UserID.Column(5)
Me.cboEmail.Value = Me.UserID.Column(6)
End Sub
I created a form for Laptop table and on that form so that I can show user assigned if any I created 6 combo boxes that are bound to the UserID Field
by way of query. In this form the User ID is column 0. it works great.
MY Code:
Private Sub Form_Current()
Me.cboFName.Value = Me.UserID.Column(1)
Me.cboLName.Value = Me.UserID.Column(2)
Me.cboDept.Value = Me.UserID.Column(3)
Me.cboEXT.Value = Me.UserID.Column(4)
Me.cboCellPhone.Value = Me.UserID.Column(5)
Me.cboEmail.Value = Me.UserID.Column(6)
End Sub
Private Sub Form_Open(Cancel As Integer)
Me.cboFName.Value = Me.UserID.Column(1)
Me.cboLName.Value = Me.UserID.Column(2)
Me.cboDept.Value = Me.UserID.Column(3)
Me.cboEXT.Value = Me.UserID.Column(4)
Me.cboCellPhone.Value = Me.UserID.Column(5)
Me.cboEmail.Value = Me.UserID.Column(6)
End Sub
Private Sub UserID_AfterUpdate()
Me.cboFName.Value = Me.UserID.Column(1)
Me.cboLName.Value = Me.UserID.Column(2)
Me.cboDept.Value = Me.UserID.Column(3)
Me.cboEXT.Value = Me.UserID.Column(4)
Me.cboCellPhone.Value = Me.UserID.Column(5)
Me.cboEmail.Value = Me.UserID.Column(6)
End Sub
Works Great........
So I then decided for ease of use to do it the for the computers table but with a twist I rearranged the columns so the when you click on the arrow of
the UserID field, it shows you the list but the last name is first followed by the first name and than the UserID which I believe to now be column 2.
I also rearranged the query to match the columns, but it does not work. In the properties of the UserID form field I changed the bound colum to 2. But
if I change it to 1 the user ID show up in the right field but none of the other info.
Here is my new code
Private Sub cboLocationID_NotInList(NewData As String, Response As Integer)
On Error GoTo cboLocationID_NotInList_Err
Dim intAnswer As Integer
Dim strSQL As String
intAnswer = MsgBox("The Loaction ID " & Chr(34) & NewData & _
Chr(34) & " is not currently in loaction list." & vbCrLf & _
"Would you like to add the new LoactionID to the list now?" _
, vbQuestion + vbYesNo, "Location ID")
If intAnswer = vbYes Then
strSQL = "INSERT INTO tbl_Location([LocationID]) " & _
"VALUES ('" & NewData & "');"
DoCmd.SetWarnings False
DoCmd.RunSQL strSQL
DoCmd.SetWarnings True
MsgBox "The new location has been added to the list." _
, vbInformation, "Location ID"
Response = acDataErrAdded
Else
MsgBox "Please choose a Location ID from the list." _
, vbInformation, "LocationID"
Response = acDataErrContinue
Me.cboLocationID.Undo
End If
cboLocationID_NotInList_Exit:
Exit Sub
cboLocationID_NotInList_Err:
MsgBox Err.Description, vbCritical, "Error"
Resume cboLocationID_NotInList_Exit
End Sub
Private Sub cmdNewUser_Click()
DoCmd.OpenForm "frm_UserSearch_Dialog", acNormal
End Sub
Private Sub Form_BeforeUpdate(Cancel As Integer)
If Not Me.NewRecord Then
If MsgBox("Changes have been made to this record" _
& vbCrLf & "Do you want to save these changes?" _
, vbYesNo + vbDefaultButton2, "Changes Made...") = vbYes Then
DoCmd.RunCommand acCmdSaveRecord
Else
Cancel = True
Me.Undo
Me.cboLName.Value = Me.UserID.Column(0)
Me.cboFName.Value = Me.UserID.Column(1)
Me.cboDept.Value = Me.UserID.Column(3)
Me.cboEXT.Value = Me.UserID.Column(4)
Me.cboCellPhone.Value = Me.UserID.Column(5)
Me.cboEmail.Value = Me.UserID.Column(6)
End If
End If
End Sub
Private Sub Form_Current()
Me.cboLName.Value = Me.UserID.Column(0)
Me.cboFName.Value = Me.UserID.Column(1)
Me.cboDept.Value = Me.UserID.Column(3)
Me.cboEXT.Value = Me.UserID.Column(4)
Me.cboCellPhone.Value = Me.UserID.Column(5)
Me.cboEmail.Value = Me.UserID.Column(6)
End Sub
Private Sub Form_Open(Cancel As Integer)
Me.cboLName.Value = Me.UserID.Column(0)
Me.cboFName.Value = Me.UserID.Column(1)
Me.cboDept.Value = Me.UserID.Column(3)
Me.cboEXT.Value = Me.UserID.Column(4)
Me.cboCellPhone.Value = Me.UserID.Column(5)
Me.cboEmail.Value = Me.UserID.Column(6)
End Sub
Private Sub UserID_AfterUpdate()
Me.cboLName.Value = Me.UserID.Column(0)
Me.cboFName.Value = Me.UserID.Column(1)
Me.cboDept.Value = Me.UserID.Column(3)
Me.cboEXT.Value = Me.UserID.Column(4)
Me.cboCellPhone.Value = Me.UserID.Column(5)
Me.cboEmail.Value = Me.UserID.Column(6)
End Sub