473,320 Members | 1,817 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

MS Access 2002: Go to newly added record from form2 to form 1

Hi,

I would appriceate any help to correct the code error that I am getting
for the onclick event of a cmd button. I have two forms. Main Form
"frmQuestion" and form 2 "SfrmQuestion". FrmQuestion shows the details
about Question and by clicking on one for the cmd button on this form
opens up SfrmQuestions that lets me add new questions. The frmQuestion
Form remains opened at the backend. My problem is when I save the
question in srmQuestion I want to go to the same added record in
frmQuestion by clicking on saveRecord cmd button which closes the
sfrmquestion Form. This is the code I have in sfrmQuestion's cmdbutton
cmdSaveRecord. I keep on getting an error

Private Sub cmdSaveRecord_Click()
DoCmd.Save
'Dim rs As DAO.Recordset

With Forms![frmQuestion]
..Requery
Set rs = Forms![frmQuestion].RecordsetClone

rs.FindFirst "QuestionID = " & Me.QuestionID
If rs.NoMatch Then
MsgBox "Not found."
Else
rs.Bookmark = Me.Bookmark
End If
Set rs = Nothing
End With

DoCmd.Close

End Sub

Mar 16 '06 #1
3 2084

"Kaur" <ka***@saic.com> wrote in message
news:11**********************@j52g2000cwj.googlegr oups.com...
Hi,

I would appriceate any help to correct the code error that I am getting
for the onclick event of a cmd button. I have two forms. Main Form
"frmQuestion" and form 2 "SfrmQuestion". FrmQuestion shows the details
about Question and by clicking on one for the cmd button on this form
opens up SfrmQuestions that lets me add new questions. The frmQuestion
Form remains opened at the backend. My problem is when I save the
question in srmQuestion I want to go to the same added record in
frmQuestion by clicking on saveRecord cmd button which closes the
sfrmquestion Form. This is the code I have in sfrmQuestion's cmdbutton
cmdSaveRecord. I keep on getting an error

Private Sub cmdSaveRecord_Click()
DoCmd.Save
'Dim rs As DAO.Recordset

With Forms![frmQuestion]
.Requery
Set rs = Forms![frmQuestion].RecordsetClone

rs.FindFirst "QuestionID = " & Me.QuestionID
If rs.NoMatch Then
MsgBox "Not found."
Else
rs.Bookmark = Me.Bookmark
End If
Set rs = Nothing
End With

DoCmd.Close

End Sub


You don't say what the error is, but if a sub may generate an error then you
should put some basic error handling in. I am 95% sure I can see what
you're doing but wonder why the form is named "SfrmQuestion" hopefully this
has absolutely nothing to do with subforms and is simply some type of popup
data-entry form.
If so, then you could code like this:
Private Sub cmdSaveRecord_Click()

On Error GoTo Err_Handler

Dim strFind As String
Dim lngQID As Long

' Save this record if it needs it
If Me.Dirty = True Then
Me.Dirty = False
End If

' Get the current QuestionID
lngQID = Nz(Me!QuestionID, 0)

' Check we have a valid ID
If lngQID > 0 Then
DoCmd.Close acForm, Me.Name
Else
Exit Sub
End If

With Forms!frmQuestion
.Requery
strFind = "QuestionID=" & CStr(lngQID)
.RecordsetClone.FindFirst strFind
If .RecordsetClone.NoMatch Then
MsgBox "Cannot locate record"
Else
.Bookmark = .RecordsetClone.Bookmark
End If
.SetFocus
End With

Exit_Handler:
Exit Sub

Err_Handler:
MsgBox Err.Description, vbExclamation, "Error No: " & Err.Number
Resume Exit_Handler

End Sub
Mar 16 '06 #2
Thanks for such a quick response. I updated the code. Now I am getting
the error: Searching records using the list box can not find the form
frmQuestion referred to in a macro expression or visual basic code."
May be I did not give enough details of the forms.
Form 1 is a search form to search for all the surveys in db. It has an
unbound list box that displays all the surveys. Clicking on one of the
surveys opens up 2nd form.
This form "frmQuestions" has all the questions related to the survey.
This form has an unbound list box that displays all the relevant
questions. Underneath the list box is Question text in combo box,
question no as it appers in the survey (a text box). This form has a
subForm that displays the subquestions associated with each Question.
The form "frmQuestion" has a cmd button which opens the Form3
"frmAddQuestions".
This form gets the survey key from tblSurvey and has a subform called
sfrmAddQuestions where users does the data entry for a question. I
created this type of form so that I can still add the question for the
relevant Survey.
From here users choose the questions from a combo box and if the

question is not in the combo box then it allows the users to add the
question. This form has cmdSaveRecord cmd button where I added the
code and still getting the error.

Any help would be appreciated.

Mar 16 '06 #3

"Kaur" <ka***@saic.com> wrote in message
news:11**********************@p10g2000cwp.googlegr oups.com...
Thanks for such a quick response. I updated the code. Now I am getting
the error: Searching records using the list box can not find the form
frmQuestion referred to in a macro expression or visual basic code."
May be I did not give enough details of the forms.
Form 1 is a search form to search for all the surveys in db. It has an
unbound list box that displays all the surveys. Clicking on one of the
surveys opens up 2nd form.
This form "frmQuestions" has all the questions related to the survey.
This form has an unbound list box that displays all the relevant
questions. Underneath the list box is Question text in combo box,
question no as it appers in the survey (a text box). This form has a
subForm that displays the subquestions associated with each Question.
The form "frmQuestion" has a cmd button which opens the Form3
"frmAddQuestions".
This form gets the survey key from tblSurvey and has a subform called
sfrmAddQuestions where users does the data entry for a question. I
created this type of form so that I can still add the question for the
relevant Survey.
From here users choose the questions from a combo box and if the

question is not in the combo box then it allows the users to add the
question. This form has cmdSaveRecord cmd button where I added the
code and still getting the error.

Any help would be appreciated.


My head is starting to ache with all that! I re-read twice and still don't
quite get it. Perhaps someone else can step in, but in any case, use the
bulk of my code with the structure and error handling. You could also use
the following function to check whether you have the expected form open,
before you call Forms!MyForm ... blah,blah,blah

Public Function IsFormLoaded(strName As String)
IsFormLoaded = (SysCmd(acSysCmdGetObjectState, acForm, strName) <> 0)
End Function


Private Sub cmdSaveRecord_Click()

On Error GoTo Err_Handler

Dim strFind As String
Dim lngQID As Long

' Save this record if it needs it
If Me.Dirty = True Then
Me.Dirty = False
End If

' Get the current QuestionID
lngQID = Nz(Me!QuestionID, 0)

' Check we have a valid ID
If lngQID > 0 Then
DoCmd.Close acForm, Me.Name
Else
Exit Sub
End If

MsgBox "Question ID=" & Cstr(lngQID) & _
vbCrLf & "Now what?"
Exit_Handler:
Exit Sub

Err_Handler:
MsgBox Err.Description, vbExclamation, "Error No: " & Err.Number
Resume Exit_Handler

End Sub
Mar 16 '06 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: Tony Stoker | last post by:
I have a .Net web app that adds a record to a SQL database. After the user adds their record I want to have a link that will link them to their new record! The recordID is a AutoNumber in the...
0
by: Miguelito Bain | last post by:
hi everybody- i've got a conundrum... i inherited some old databases, and i'm trying to convert them. i run office xp with access 2002, and all of the databases i manage are either in 97...
6
by: Peter Frost | last post by:
Please help I don't know if this is possible but what I would really like to do is to use On Error Goto to capture the code that is being executed when an error occurs. Any help would be much...
0
by: dlieu | last post by:
I've found an odd situation in where the Load event of the active form fires (after the Unload event) when Access is closed. I am able to reproduce this situation in Access 2002 SP3 and Access 2003...
52
by: Neil | last post by:
We are running an Access 2000 MDB with a SQL 7 back end. Our network guy is upgrading to Windows Server 2003 and wants to upgrade Office and SQL Server at the same time. We're moving to SQL Server...
4
by: jg1130 | last post by:
Greetings all, Here's my problem... I've built a small Access database that I placed on my server. I have one workstation connected to the database. The folder that the database is in on...
2
by: Frav | last post by:
The Reps team have been experiencing that Access 2002 unexpectedly quits while working and also lots of Corruption Failures and "Record lock can not update" messages since the upgrade from...
4
by: etuncer | last post by:
Hello All, I have Access 2003, and am trying to build a database for my small company. I want to be able to create a word document based on the data entered through a form. the real question is...
12
by: tekctrl | last post by:
Environment; Win2K PC with 1Gb of RAM and plenty of HD space running Access 2002 Issue; Access presents a blank data entry form in the Forms view when the New Record icon is used. However, it...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.