0
votes

I am creating an Access Database formed out of two things - Software and Licences. Licenses are attached to Software via their ID.

I have a form created for Software, and would like to create a button that, when clicked, opens a fresh "Add License" form which pre-populates the Software ID and that people can fill in the rest of the information on. I've been using Macros from a similar Office 2016 Template and it continually falls over when trying to put this information into the new License form.

I've attached a screenshot of my macro below - I've gone through many iterations of this now and the error I get is 30024, which appears to indicate that it cannot find the field to put the SoftwareID into in the newly opened form. I've also set the "Control Name" to just "SoftwareID" as this was also suggested elsewhere but this also does not work.

Any suggestions?

Screenshot of Macro in question

1
I would highly suggest converting your code to Visual Basic. It will be much easier to diagnose. - Pants

1 Answers

0
votes

I couldn't get it to work using the embedded macro so I used a VBA macro instead which worked :). To do this (assuming you haven't done it before):

  • Open your "Software" form in design view
  • Show the property sheet (Ribbon -> Design Tab)
  • Click on your button
  • Click the "Event" tab on the Property sheet
  • Delete the "On Click" event
  • Right click your button and click "Build Event"
  • From the "Choose Builder" popup box, click "Code Builder"
  • Assuming you don't have any other macros, your code should look just like mine with the only differences being the name of your button (mine is Command163)

p.s. I Couldnt get the code tags to display properly so i just added some line breaks. Apologies for the improper indenting.

Option Compare Database

Private Sub Command163_Click()

DoCmd.RunCommand acCmdSaveRecord

openFreshAddLicenseForm (Me.ID)

End Sub

Public Function openFreshAddLicenseForm(ID As Integer)

On Error GoTo Macro1_Err

DoCmd.OpenForm "Add License"

DoCmd.GoToRecord , "", acNewRec

Forms![Add License]!SoftwareID = ID

Macro1_Exit:

Exit Function

Macro1_Err:

MsgBox Error$

Resume Macro1_Exit

End Function