Full Version: Multiple tables
UtterAccess Discussion Forums > Microsoft® Access > Access Tables + Relationships
mdedmunds
I need to have a form update information on two tables. This database is used for peer evaluations. I need to know if all employee are entering the data. I need to be able to have the date the form was submitted, the month the evaluation is for, and the person they are evaluating to populate into two different table. Because they are promised this is confidential we are created a linked table with the submitters information for tracking purposes only. This table can't contain any of the scoring information, just as the scoring table can't contain the submitters name.

I have this being done now by having the employee click a button after filling out the evaluation, that then opens a second form where they have to put in the month and the person they are evaluating again. Since we have this split I can not be 100% sure they are putting the right employees name when they say they finished an evaluation.

Any suggestions?
treeless
How about inserting a record into the 2nd table in the first form's On Close or On Unload event. Better yet, instead of a second table, why not just use a query based on the 1st table which omits the sensitive information.
mdedmunds
I wanted to do the query solution originally, however HR states that is not secure enough because I can find the information that way with more ease.

Currently on the on close click I have another command. I am still pretty new to this. Can I have two functions for the same command?
treeless
yes, you can have any number of function for the same command. It would probably look something like this.
CODE
Private Sub cmdSubmit_Click()
     Dim sql as String

     'assumes text field for txtMonth, number field for txtPersonEvaluatedID
     sql = "INSERT INTO [SecondTableName] SET [MonthField]='" & Me!txtMonth & "', _
            [PersonEvaluatedID]=" & Me!txtPersonEvaluatedID & ";"
     CurrentDb.Execute sql
    
     DoCmd.Close
      
End Sub
mdedmunds
Thank you for all the help, I think I am just about there. I get an error when I try to run it now. There is a syntax error in the execute line. If I mouse over the execute line the data shows up, so I know it is pulling the right information. Here is the code I have

Private Sub cmdAdd_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
Dim SQL As String

'assumes text field for txtMonth, number field for txtPersonEvaluatedID
SQL = "INSERT INTO [Table1] SET [MonthID]='" & Me!cboMonth & "', _[CoachID]=" & Me!cboCoach & ";"
CurrentDb.Execute SQL




DoCmd.Close


End Sub
R. Hicks
Why are you using the "On Mouse Down" event ???
You should be using the "On Click" event of the button ....

Also .. the line should be:
CODE
SQL = "INSERT INTO [Table1] SET [MonthID]=" & Me.cboMonth & ", [CoachID]=" & Me.cboCoach & ";"

Assuming that both "MonthID and "CoachID" are numeric datatypes ...

And ... this line:
CurrentDb.Execute SQL

Should be:
CurrentDb.Execute SQL, dbFailOnError

RDH

Edited by: R. Hicks on 06.27.04.
mdedmunds
I moved it because I got an error stating ambiguous name detected
; cmd_addClick when I added it to the click command.

I have moved it back and get the same error, here is all the code

Private Sub cmdAdd_Click()
On Error GoTo Err_cmdAdd_Click

If CheckValues = True Then
DoCmd.GoToRecord , , acNewRec
cboMonth.SetFocus
DisableControls
Else
Exit Sub
End If

Exit_cmdAdd_Click:
Exit Sub

Err_cmdAdd_Click:
MsgBox Err.Description
Resume Exit_cmdAdd_Click
End Sub

Private Sub cmdAdd_Click()
Dim SQL As String

'assumes text field for txtMonth, number field for txtPersonEvaluatedID
SQL = "INSERT INTO [Table1] SET [MonthID]=" & Me.cboMonth & ", [CoachID]=" & Me.cboCoach & ";"
CurrentDb.Execute SQL, dbFailOnError



DoCmd.Close


End Sub
R. Hicks
I what you posted .. shows the "ambiguous name" ...

You can not have 2 procedures with the same name ... (that's "ambiguous")

If the code in the already existing procedure is needed ... you simply need to "add" to that exist procedure ...

But it appears you have two completely different things going on here with this "Add" button.
Do you want to go to a new record and set focus to "cboMonth" if "CheckValues" is True ...
And if "CheckValues" is not True ... execute the append query and close the form ????

If the above is true .. then this is needed:
CODE
Private Sub cmdAdd_Click()

On Error GoTo Err_cmdAdd_Click

Dim SQL As String



SQL = "INSERT INTO [Table1] SET [MonthID]=" & Me.cboMonth & ", [CoachID]=" & Me.cboCoach & ";"



If CheckValues = True Then

  DoCmd.GoToRecord , , acNewRec

  Me.cboMonth.SetFocus

  DisableControls

Else

  CurrentDb.Execute SQL, dbFailOnError

  DoCmd.Close acForm, Me.Name

End If



Exit_cmdAdd_Click:

  Exit Sub



Err_cmdAdd_Click:

  MsgBox Err.Number & ":" & Err.Description

  Resume Exit_cmdAdd_Click



End Sub

The above is again assuming that "MonthID" and "CoachID" are both numeric datatypes ...

Another thing I'm not sure of in the above example is .. I don't know what "CheckValues" is ...
If it's a checkbox on the form ... change it to ... Me.CheckValues
If it's a variable name ... then it's OK ..

Also ...you have the comment line:
'assumes text field for txtMonth, number field for txtPersonEvaluatedID

Neither of these controls are in this procedure ?????

RDH

Edited by: R. Hicks on 06.27.04.
mdedmunds
The add button verifies the boxes all have scores in them, then opens a blank form for the employee to fill out again on someone else.

I continue to get an error that there is an error in the statement. I have included the whole db this time, might be easier than me trying to explain what I am doing. The form I am trying to change right now is the fEcareMain. I am just testing so for now I just have it going to the table1 table.

Again I appreciate your help
R. Hicks
"TextID" is a "Text" datatype ... so the sytax had to be changed in the SQL ...

Also I added a vertical scroll bar to the form .. as I could not get to your "Add" button at 1024 x 768 resolution.
You can remove it if you like ...

RDH
mdedmunds
Thanks again for all your help. I am no longer getting errors, however the data is not going into the table1 table. Since I need all entries to go unless there is an error, should I move the execute statement?
R. Hicks
I havent a clue as to what you are wanting to do ...

It appears you want the literal month name and the Coach ID appended to Table1 ...

I have altered the procedure to do this.
I see no need for the month table ... but I used it as you did.
The Month number and the Month name can be gotten without this table to populate the combo values ...

Now ... I test the SQL in this and it works ...
But I haven't a clue as to if your function named "CheckValues" is returning the correct result.

RDH
mdedmunds
Thanks for your help, and sorry for the long delay in my responding. This project got put on the back burner. The function for checkvalues is to force all the fields to be filled out. Once the form is submitted all the fields are disable again, until the field above it has informaiton entered into it.

I am not sure if I am missing a step, however when I fill in the form and submit it, the data is not going into the table1 table. Have I missed a step?
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.