[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 245
  • Last Modified:

Move to previous record of a subform VBA

I am doing error checking after clicking on a command button. The user is adding records to a subform and is then clicking the command button on main form to update the database.If there are null values on the subform I send an error message. However, if the user inadvertently added a "Blank" record, I want to move to the previous record and continue with the code. I have the correct code, but I don't know how to move to previous record of the subform.
If Forms!frmActive.Company_Information.Form!strPlanExt = "" Or IsNull(Forms!frmActive.Company_Information.Form!strPlanExt) Then
    If Forms!frmActive.Company_Information.Form!strPlanCD = "" Or IsNull(Forms!frmActive.Company_Information.Form!strPlanCD) Then
        If Forms!frmActive.Company_Information.Form!strGroupExt = "" Or IsNull(Forms!frmActive.Company_Information.Form!strGroupExt) Then
            MsgBox "You are missing information for a Line Item. Please correct.", vbInformation, "Line Items"
        Else
            **********'This code fails. says the form isn't open
            DoCmd.GoToRecord acDataForm, "Forms!frmActive.Company_Information.Form", acPrevious
        End If
    End If
End If


0
smm6809
Asked:
smm6809
  • 3
  • 3
1 Solution
 
Rey Obrero (Capricorn1)Commented:
try this, just modifying the "Else" part of the codes


        Else
            **********'This code fails. says the form isn't open
            me.Company_Information.setfocus
            DoCmd.GoToRecord acDataForm,  , acPrevious
0
 
smm6809Author Commented:
error :
this object requires an object name argument
0
 
Rey Obrero (Capricorn1)Commented:
which line ?



        Else
            **********'This code fails. says the form isn't open
            me.Company_Information.setfocus
            DoCmd.GoToRecord , , acPrevious
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
smm6809Author Commented:
docmd gotorecord
0
 
Rey Obrero (Capricorn1)Commented:
try the last posted codes.
0
 
Dale FyeCommented:
Doesn't answer your question, but instead of the following syntax:

IF Forms!frmActive.Company_Information.Form!strPlanExt = "" Or IsNull(Forms!frmActive.Company_Information.Form!strPlanExt) Then

I would use:

IF Forms!frmActive.Company_Information.Form!strPlanExt & "" = "" Then

or you could use

IF LEN(Forms!frmActive.Company_Information.Form!strPlanExt & "") = 0 Then

Either of these techniques works, and is easier to read than the syntax you are currently using.  When you use the "&" to concatenate an empty string to another value you actually append the empty string to the value, even if the other value is a NULL.  Because of this, you can identify whether a value is NULL or an empty string by doing the concatenation indicated above, and then checking to see whether it is an empty string, or whether the length = 0.
0
 
smm6809Author Commented:
and thanks also Fayed
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 3
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now