Open Form and get record.

G

Guest

I have written the following code (I am new at this so bear with me Please).
Basically I want to first Close the form "Bibliotheca" and then reopen it
showing the record that it was on before it closed. When I run it it tells me
"Mismatch", the field BookID is a number field so I can't understand why it
wont accept it.

I hope that someone can help me.

Private Sub Close_Edition_Number_Form_Click()
On Error GoTo Err_Close_Edition_Number_Form_Click

Dim stDocName As String
Dim stLinkCriteria As String
Dim stMyName As String
Dim intBookNum As Integer


stMyName = "Edition"
stDocName = "Bibliotheca"
intBookNum = "Bibliotheca!BookID"

If Len("" & stMyName) < 1 Then
DoCmd.CancelEvent
Else

DoCmd.Save
DoCmd.Close acForm, stDocName
DoCmd.OpenForm stDocName, , , "BookID = intBookNum"
DoCmd.Close acForm, stMyName

End If

Exit_Close_Edition_Number_Form_Click:
Exit Sub

Err_Close_Edition_Number_Form_Click:
MsgBox Err.Description
Resume Exit_Close_Edition_Number_Form_Click

End Sub

Steven.
 
M

Marshall Barton

StevenIpek. said:
I have written the following code (I am new at this so bear with me Please).
Basically I want to first Close the form "Bibliotheca" and then reopen it
showing the record that it was on before it closed. When I run it it tells me
"Mismatch", the field BookID is a number field so I can't understand why it
wont accept it.

I hope that someone can help me.

Private Sub Close_Edition_Number_Form_Click()
On Error GoTo Err_Close_Edition_Number_Form_Click

Dim stDocName As String
Dim stLinkCriteria As String
Dim stMyName As String
Dim intBookNum As Integer


stMyName = "Edition"
stDocName = "Bibliotheca"
intBookNum = "Bibliotheca!BookID"

If Len("" & stMyName) < 1 Then
DoCmd.CancelEvent
Else

DoCmd.Save
DoCmd.Close acForm, stDocName
DoCmd.OpenForm stDocName, , , "BookID = intBookNum"
[snip]


I think you need to change two lines

intBookNum = FormsBibliotheca!BookID

and

DoCmd.OpenForm stDocName, , , "BookID = " & intBookNum
 
G

Guest

Thank you for having replied so promptly Marshall,
I have changed the two lines, unfortunately a message box comes up with
"Object required", is there something else I can do?

Marshall Barton said:
StevenIpek. said:
I have written the following code (I am new at this so bear with me Please).
Basically I want to first Close the form "Bibliotheca" and then reopen it
showing the record that it was on before it closed. When I run it it tells me
"Mismatch", the field BookID is a number field so I can't understand why it
wont accept it.

I hope that someone can help me.

Private Sub Close_Edition_Number_Form_Click()
On Error GoTo Err_Close_Edition_Number_Form_Click

Dim stDocName As String
Dim stLinkCriteria As String
Dim stMyName As String
Dim intBookNum As Integer


stMyName = "Edition"
stDocName = "Bibliotheca"
intBookNum = "Bibliotheca!BookID"

If Len("" & stMyName) < 1 Then
DoCmd.CancelEvent
Else

DoCmd.Save
DoCmd.Close acForm, stDocName
DoCmd.OpenForm stDocName, , , "BookID = intBookNum"
[snip]


I think you need to change two lines

intBookNum = FormsBibliotheca!BookID

and

DoCmd.OpenForm stDocName, , , "BookID = " & intBookNum
 
M

Marshall Barton

Stupid fingers can't type. I left out an exclamation mark.

intBookNum = Forms!Bibliotheca!BookID
--
Marsh
MVP [MS Access]


StevenIpek. said:
Thank you for having replied so promptly Marshall,
I have changed the two lines, unfortunately a message box comes up with
"Object required", is there something else I can do?

StevenIpek. said:
I have written the following code (I am new at this so bear with me Please).
Basically I want to first Close the form "Bibliotheca" and then reopen it
showing the record that it was on before it closed. When I run it it tells me
"Mismatch", the field BookID is a number field so I can't understand why it
wont accept it.

I hope that someone can help me.

Private Sub Close_Edition_Number_Form_Click()
On Error GoTo Err_Close_Edition_Number_Form_Click

Dim stDocName As String
Dim stLinkCriteria As String
Dim stMyName As String
Dim intBookNum As Integer


stMyName = "Edition"
stDocName = "Bibliotheca"
intBookNum = "Bibliotheca!BookID"

If Len("" & stMyName) < 1 Then
DoCmd.CancelEvent
Else

DoCmd.Save
DoCmd.Close acForm, stDocName
DoCmd.OpenForm stDocName, , , "BookID = intBookNum"
[snip]
Marshall Barton said:
I think you need to change two lines

intBookNum = FormsBibliotheca!BookID

and

DoCmd.OpenForm stDocName, , , "BookID = " & intBookNum
 
G

Guest

Hi Marshall,

Thanks for the edited version, It worked like a charm! I am sorry that I
keep on asking for help, the problem is that I have lost the book on Access
(I loand it to someone and they have lost it) so I am trying to work out what
all the commands are whilst trying to build a database for all my books, it's
comming on but very slowly, anyway thanks again for your invaluable help.

Steve.

Marshall Barton said:
Stupid fingers can't type. I left out an exclamation mark.

intBookNum = Forms!Bibliotheca!BookID
--
Marsh
MVP [MS Access]


StevenIpek. said:
Thank you for having replied so promptly Marshall,
I have changed the two lines, unfortunately a message box comes up with
"Object required", is there something else I can do?

StevenIpek. wrote:
I have written the following code (I am new at this so bear with me Please).
Basically I want to first Close the form "Bibliotheca" and then reopen it
showing the record that it was on before it closed. When I run it it tells me
"Mismatch", the field BookID is a number field so I can't understand why it
wont accept it.

I hope that someone can help me.

Private Sub Close_Edition_Number_Form_Click()
On Error GoTo Err_Close_Edition_Number_Form_Click

Dim stDocName As String
Dim stLinkCriteria As String
Dim stMyName As String
Dim intBookNum As Integer


stMyName = "Edition"
stDocName = "Bibliotheca"
intBookNum = "Bibliotheca!BookID"

If Len("" & stMyName) < 1 Then
DoCmd.CancelEvent
Else

DoCmd.Save
DoCmd.Close acForm, stDocName
DoCmd.OpenForm stDocName, , , "BookID = intBookNum"
[snip]
Marshall Barton said:
I think you need to change two lines

intBookNum = FormsBibliotheca!BookID

and

DoCmd.OpenForm stDocName, , , "BookID = " & intBookNum
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top