Fred Fisher
asked on
Unable to get DoCmd.OpenForm "frmInstrumentServiceRecords" to work.
I have a form frmInstruments that lists a number of different instruments in the table tblInstruments. Located on frmInstruments is a command button btnAddEditMaintenanceHistory that when clicked I would like it to open frmInstrumentServiceRecords only for the the instrument currently displayed in frmInstruments. Seemed easy enough but after two days I am stumped. Below is the code for the click event for btnAddEditMaintenanceHistory.
Private Sub btnAddEditMaintenanceHistory_Click()
Dim vInstrumentServiced As String
Dim vSQL As String
vInstrumentServiced = Me.InstModel
vSQL = "[ServInstModel] = " & vInstrumentServiced
DoCmd.OpenForm "frmInstrumentServiceRecords", , , vSQL
End Sub
Me.InstModel is the Instrument field name on frmInstruments. ServInstModel is the field name on frmInstrumentServiceRecords that needs to be = to Me.InstModel.
When I run this I get a runtime error 3075 "Syntax error (missing operator) in query expression 'ServInstModel = Ampico B Mason & Hamlin 5'8" Grand.
Any thoughts?
Private Sub btnAddEditMaintenanceHistory_Click()
Dim vInstrumentServiced As String
Dim vSQL As String
vInstrumentServiced = Me.InstModel
vSQL = "[ServInstModel] = " & vInstrumentServiced
DoCmd.OpenForm "frmInstrumentServiceRecords", , , vSQL
End Sub
Me.InstModel is the Instrument field name on frmInstruments. ServInstModel is the field name on frmInstrumentServiceRecords that needs to be = to Me.InstModel.
When I run this I get a runtime error 3075 "Syntax error (missing operator) in query expression 'ServInstModel = Ampico B Mason & Hamlin 5'8" Grand.
Any thoughts?
ASKER
Upon further review I have several issues in my tblInstruments. That is Ampico Mason & Hamlin 5'8" Grand is three pieces of information so I will need to split that up into Instrument Name (Ampico B Mason & Hamlin), Instrument Type (Grand Piano), and Instrument Dimensions.That I can handle.
In the meantime I changed Ampico Mason & Hamlin 5'8" Grand to Ampico B Mason & Hamlin. Now when I run
vSQL = "[ServInstModel] = " & Replace(vInstrumentServiced, """", """""")
This returns: vSQL = "[ServInstModel] = Ampico B Mason & Hamlin"The DoCmd.OpenForm "frmInstrumentServiceRecords", , , vSQL results in a slightly different error
"Runtime error 3075 "Syntax error (missing operator) in query expression "[ServInstModel] = Ampico B Mason & Hamlin".
Yes, the single-quotes were missing:
vSQL = "[ServInstModel] = '" & Replace(vInstrumentServiced, """", """""") & "'"
ASKER
Yes. You'll need a field in the service table to match InstrumentID (Long) to hold the foreign key.
ASKER
Isn't the foreign key ServiceID?
From the names of the fields: No. Should be ServiceInstID or similar.
But I don't have your tables ... you do.
But I don't have your tables ... you do.
ASKER
I have stripped the Instrument Database from the Music Manager database and it is attached.Instrument.accdb
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Open in new window