repeating date of previous record

R

randria

Hello,
I have a Date control called SDate on a subform linked by Main File Id with
the main form, I would like to repeat the value of SDate that has the same
Main File Id for new record. this is what I tried but I get error msg
Run-time error '3075':
Syntax error (missing operator) in query expression 'Main File Id'

Private Sub SDate_Click()
Dim PrevDate As Date

If Me.NewRecord Then
PrevDate = DLookup("SDate", "MFPDate", "Main File Id=" & [Main File Id])
Me.SDate = PrevDate
Else
End If
End Sub

Many thanks.
 
M

Marshall Barton

randria said:
Hello,
I have a Date control called SDate on a subform linked by Main File Id with
the main form, I would like to repeat the value of SDate that has the same
Main File Id for new record. this is what I tried but I get error msg
Run-time error '3075':
Syntax error (missing operator) in query expression 'Main File Id'

Private Sub SDate_Click()
Dim PrevDate As Date

If Me.NewRecord Then
PrevDate = DLookup("SDate", "MFPDate", "Main File Id=" & [Main File Id])
Me.SDate = PrevDate
Else
End If
End Sub


That sounds like Main File Id is a Text field. If so, it
should be:

... , "Main File Id=""" & [Main File Id] & """")
 
R

randria

Thanks for your prompt reply, Main File Id is a number field ( Long Integer ).

Marshall Barton said:
randria said:
Hello,
I have a Date control called SDate on a subform linked by Main File Id with
the main form, I would like to repeat the value of SDate that has the same
Main File Id for new record. this is what I tried but I get error msg
Run-time error '3075':
Syntax error (missing operator) in query expression 'Main File Id'

Private Sub SDate_Click()
Dim PrevDate As Date

If Me.NewRecord Then
PrevDate = DLookup("SDate", "MFPDate", "Main File Id=" & [Main File Id])
Me.SDate = PrevDate
Else
End If
End Sub


That sounds like Main File Id is a Text field. If so, it
should be:

... , "Main File Id=""" & [Main File Id] & """")
 
R

randria

to elaborate, MFPDate is a query that returns the Max of SDate having Main
File Id (long integer). any help is appreciated in debbuging this error
'3075'.
Thanks.

randria said:
Thanks for your prompt reply, Main File Id is a number field ( Long Integer ).

Marshall Barton said:
randria said:
Hello,
I have a Date control called SDate on a subform linked by Main File Id with
the main form, I would like to repeat the value of SDate that has the same
Main File Id for new record. this is what I tried but I get error msg
Run-time error '3075':
Syntax error (missing operator) in query expression 'Main File Id'

Private Sub SDate_Click()
Dim PrevDate As Date

If Me.NewRecord Then
PrevDate = DLookup("SDate", "MFPDate", "Main File Id=" & [Main File Id])
Me.SDate = PrevDate
Else
End If
End Sub


That sounds like Main File Id is a Text field. If so, it
should be:

... , "Main File Id=""" & [Main File Id] & """")
 
M

Marshall Barton

Sorry, I really misread your message.

The error is because the Main File Id field name contains
spaces so it must be enclosed in [ ]

... , "[Main File Id]=" & [Main File Id])
--
Marsh
MVP [MS Access]

to elaborate, MFPDate is a query that returns the Max of SDate having Main
File Id (long integer). any help is appreciated in debbuging this error
'3075'.

randria said:
Thanks for your prompt reply, Main File Id is a number field ( Long Integer ).

Marshall Barton said:
randria wrote:

Hello,
I have a Date control called SDate on a subform linked by Main File Id with
the main form, I would like to repeat the value of SDate that has the same
Main File Id for new record. this is what I tried but I get error msg
Run-time error '3075':
Syntax error (missing operator) in query expression 'Main File Id'

Private Sub SDate_Click()
Dim PrevDate As Date

If Me.NewRecord Then
PrevDate = DLookup("SDate", "MFPDate", "Main File Id=" & [Main File Id])
Me.SDate = PrevDate
Else
End If
End Sub


That sounds like Main File Id is a Text field. If so, it
should be:

... , "Main File Id=""" & [Main File Id] & """")
 
R

randria

Hi Marsh, sorry it was my mistake, the reason why I got Ren-time error '94'
was because I used SDate instead of MaxOFSDate in the query, so now it is
working well, many thanks for your help.

randria said:
Hello Marsh, I tried ....,"[Main File Id]=" &[Main File Id] but I get
Run-time error '94' Invalid use of Null, then I tried "[Main File Id]="&
nz([Main File Id]) but it does not accept. I appreciate your help.
many thanks.

Marshall Barton said:
Sorry, I really misread your message.

The error is because the Main File Id field name contains
spaces so it must be enclosed in [ ]

... , "[Main File Id]=" & [Main File Id])
--
Marsh
MVP [MS Access]

to elaborate, MFPDate is a query that returns the Max of SDate having Main
File Id (long integer). any help is appreciated in debbuging this error
'3075'.

:

Thanks for your prompt reply, Main File Id is a number field ( Long Integer ).

:

randria wrote:

Hello,
I have a Date control called SDate on a subform linked by Main File Id with
the main form, I would like to repeat the value of SDate that has the same
Main File Id for new record. this is what I tried but I get error msg
Run-time error '3075':
Syntax error (missing operator) in query expression 'Main File Id'

Private Sub SDate_Click()
Dim PrevDate As Date

If Me.NewRecord Then
PrevDate = DLookup("SDate", "MFPDate", "Main File Id=" & [Main File Id])
Me.SDate = PrevDate
Else
End If
End Sub


That sounds like Main File Id is a Text field. If so, it
should be:

... , "Main File Id=""" & [Main File Id] & """")
 

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