By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
464,299 Members | 1,142 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 464,299 IT Pros & Developers. It's quick & easy.

open form to specific record or create new record

P: 2
I have a database that I am using to store student data. There are two tables and two forms to display the data:

Tables
tbStudent
tbRE

Forms
fmStudent
fmRE

tbStudent stores basic student data, while tbRE stores specific academic data for some, but not all, students. The two tables are linked through the student ID number(stStuID), which is the key in tbStudent.

I would like to create a command button in fmStudent that opens fmRE, but to the record of the student currently displayed in fmStudent. Aside from opening fmRE to a specific record, I am also curious about what happens if a student does not have a record in fmRE. Could I have the command open fmRE to a blank record if the student doesn't have a record, so the user can enter the data to create one?

I have not used VBA very much so I am new to this level of design. I've seen some responses to this type of question, but I'm not sure how to get started with the coding.

I am using Access 2003 on Windows XP.

Thanks!
Nov 13 '06 #1
Share this Question
Share on Google+
3 Replies

MMcCarthy
Expert Mod 10K+
P: 14,534
The easiest way to do this is to use a subform on your form that is the fmRE. Bind it using the stStuID field. This will display the records for students who have them and a blank record where there is no record available.

If you try to open another form you will have problems with the ones that haven't any records. For future reference the code would be:

DoCmd.OpenForm "fmRE", , , "[stStuID]=" & Me.stStuID

I have a database that I am using to store student data. There are two tables and two forms to display the data:

Tables
tbStudent
tbRE

Forms
fmStudent
fmRE

tbStudent stores basic student data, while tbRE stores specific academic data for some, but not all, students. The two tables are linked through the student ID number(stStuID), which is the key in tbStudent.

I would like to create a command button in fmStudent that opens fmRE, but to the record of the student currently displayed in fmStudent. Aside from opening fmRE to a specific record, I am also curious about what happens if a student does not have a record in fmRE. Could I have the command open fmRE to a blank record if the student doesn't have a record, so the user can enter the data to create one?

I have not used VBA very much so I am new to this level of design. I've seen some responses to this type of question, but I'm not sure how to get started with the coding.

I am using Access 2003 on Windows XP.

Thanks!
Nov 13 '06 #2

NeoPa
Expert Mod 15k+
P: 31,770
DoCmd.OpenForm "fmRE", , , "[stStuID]=" & Me.stStuID
Or if, as I suspect, the st of stStuID stands for string, then you must add quotes around the variable in your code thus :
Expand|Select|Wrap|Line Numbers
  1. DoCmd.OpenForm "fmRE", , , "[stStuID]='" & Me.stStuID & "'"
Nov 13 '06 #3

MMcCarthy
Expert Mod 10K+
P: 14,534
Or if, as I suspect, the st of stStuID stands for string, then you must add quotes around the variable in your code thus :
Expand|Select|Wrap|Line Numbers
  1. DoCmd.OpenForm "fmRE", , , "[stStuID]='" & Me.stStuID & "'"
Good call.

I just assumed that ID would be a number. I have to stop doing that.



Mary
Nov 13 '06 #4

Post your reply

Sign in to post your reply or Sign up for a free account.