D
DoveArrow
Right now, I have a database with three tables. The first table
(tblAdvisors) has a list of advisors with some basic information about
each one (last name, first name, email address). The second table
(jtblLocationAdvisor) is a join table where the campuses that an
advisor advises for are stored (Example: John Smith advises for campus
238 and 241, so his Advisor ID and the Location Numbers he advises for
are stored in this table). The third table
(jtblAcademicProgramsByLocationAdvisor) stores the programs that an
advisor advises for on a particular campus. Each of these tables is
linked together through relationships, so that you can click on the
plus sign next to an advisor's name, and then click on the plus sign
next to one of the campuses that advisor works on, and then add or
delete programs based on campus, like so:
tblAdvisors
|_ jtblLocationAdvisor
....|_ jtblAcademicProgramsByLocationAdvisor
So that's the basics of how my database works. Now for what I'm asking
about.
I'm trying to create a form (frmNewAdvisor) that will 1) Update the
tblAdvisors table, and 2) Open a second form that can be used to
update the jtblLocationAdvisor table. To do this, I created a fourth
table called tblNewAdvisor and added it as the form's record source
(Note: I did this, because I didn't want the form to update
tblAdvisors if the user decided to cancel out. I know there are better
ways to do this, but as often as I've tried to understand those
methods, I can't get my head wrapped around them). After filling out
this form, I want the person to be able to click a button, that will
run an append query (qappCreateNewAdvisor) to append the new advisor
to tblAdvisors, have it open a second form, and append the new
advisor's Advisor ID to a text box on that form. To do that, I've
tried writing the following code:
Private Sub OK_Click()
Dim db As Database
Dim rs As Recordset
Dim strCriteria As String
Set db = CurrentDb
Set rs = db.OpenRecordset("qfltAdvisorLocations", dbOpenDynaset)
If IsNull(Me.[Last Name]) Then
MsgBox "You have not completed filling out this form."
ElseIf IsNull(Me.[First Name]) Then
MsgBox "You have not completed filling out this form."
ElseIf IsNull(Me.) Then
MsgBox "You have not completed filling out this form."
Else
Me.Refresh
DoCmd.SetWarnings False
'Create New Advisor
DoCmd.OpenQuery "qappCreateNewAdvisor"
'Select Advisor ID for frmAdvisorLocations
On Error GoTo Err_OK_Click
rs.MoveFirst
strCriteria = rs![Advisor ID]
'Open frmAdvisorLocations
DoCmd.OpenForm "frmAdvisorLocations"
Forms!frmAdvisorLocations![Advisor ID] = strCriteria
'Close frmCreateAdvisor
DoCmd.Close acForm, "frmCreateAdvisor", acSavePrompt
DoCmd.SetWarnings True
End If
Exit_OK_Click:
Set db = Nothing
Set rs = Nothing
Exit Sub
Err_OK_Click:
MsgBox Err.Description
Resume Exit_OK_Click
End Sub
The problem I'm running into is that when I click on the button, I get
an error message that says "No Current Record." However, if I click on
it a second time, it works fine. My guess is it has something to do
with the coding I've put together for running the recordset. I say
this because I'm still just learning how these work, and I've made
some pretty silly mistakes with them before, simply because I didn't
understand what was supposed to happen. Any thoughts?
(tblAdvisors) has a list of advisors with some basic information about
each one (last name, first name, email address). The second table
(jtblLocationAdvisor) is a join table where the campuses that an
advisor advises for are stored (Example: John Smith advises for campus
238 and 241, so his Advisor ID and the Location Numbers he advises for
are stored in this table). The third table
(jtblAcademicProgramsByLocationAdvisor) stores the programs that an
advisor advises for on a particular campus. Each of these tables is
linked together through relationships, so that you can click on the
plus sign next to an advisor's name, and then click on the plus sign
next to one of the campuses that advisor works on, and then add or
delete programs based on campus, like so:
tblAdvisors
|_ jtblLocationAdvisor
....|_ jtblAcademicProgramsByLocationAdvisor
So that's the basics of how my database works. Now for what I'm asking
about.
I'm trying to create a form (frmNewAdvisor) that will 1) Update the
tblAdvisors table, and 2) Open a second form that can be used to
update the jtblLocationAdvisor table. To do this, I created a fourth
table called tblNewAdvisor and added it as the form's record source
(Note: I did this, because I didn't want the form to update
tblAdvisors if the user decided to cancel out. I know there are better
ways to do this, but as often as I've tried to understand those
methods, I can't get my head wrapped around them). After filling out
this form, I want the person to be able to click a button, that will
run an append query (qappCreateNewAdvisor) to append the new advisor
to tblAdvisors, have it open a second form, and append the new
advisor's Advisor ID to a text box on that form. To do that, I've
tried writing the following code:
Private Sub OK_Click()
Dim db As Database
Dim rs As Recordset
Dim strCriteria As String
Set db = CurrentDb
Set rs = db.OpenRecordset("qfltAdvisorLocations", dbOpenDynaset)
If IsNull(Me.[Last Name]) Then
MsgBox "You have not completed filling out this form."
ElseIf IsNull(Me.[First Name]) Then
MsgBox "You have not completed filling out this form."
ElseIf IsNull(Me.) Then
MsgBox "You have not completed filling out this form."
Else
Me.Refresh
DoCmd.SetWarnings False
'Create New Advisor
DoCmd.OpenQuery "qappCreateNewAdvisor"
'Select Advisor ID for frmAdvisorLocations
On Error GoTo Err_OK_Click
rs.MoveFirst
strCriteria = rs![Advisor ID]
'Open frmAdvisorLocations
DoCmd.OpenForm "frmAdvisorLocations"
Forms!frmAdvisorLocations![Advisor ID] = strCriteria
'Close frmCreateAdvisor
DoCmd.Close acForm, "frmCreateAdvisor", acSavePrompt
DoCmd.SetWarnings True
End If
Exit_OK_Click:
Set db = Nothing
Set rs = Nothing
Exit Sub
Err_OK_Click:
MsgBox Err.Description
Resume Exit_OK_Click
End Sub
The problem I'm running into is that when I click on the button, I get
an error message that says "No Current Record." However, if I click on
it a second time, it works fine. My guess is it has something to do
with the coding I've put together for running the recordset. I say
this because I'm still just learning how these work, and I've made
some pretty silly mistakes with them before, simply because I didn't
understand what was supposed to happen. Any thoughts?