[SOLVED] VBA Open Record to Form
Hi there...I have an issue I'm struggling with...hoping someone can help.
I have a Query that outputs a simple list of records in Datasheet view, and I have an embedded macro that opens an individual record from that datasheet in a Form when you click on it....pretty simple stuff.
The embedded macro passes the value from the field Doc ID to the form's record source field of the same name to ensure that the record clicked is the same one that opens in the form. The form displays the record in edit mode.
The Doc ID field is captured from a table record that is a primary key field, with formatting added to the front (e.g. record 1 displays as WPS001 etc using the format "WPS"000.)
The embedded macro works fine using the where condition: ="[Doc ID]=" & "" & [Doc ID] & ""
The problem...I have tried to replicate the embedded macro in VBA...this is where I get stuck. I have tried multiple variations and suggestions from other sites, and all I can get the form to do is open on a blank record.
For example, I have tried:
DoCmd.OpenForm "FrmCustomerExisting", _
WhereCondition:="[Doc ID]=" & "" & [Doc ID] & ""
DoCmd.OpenForm "FrmCustomerExisting", _
WhereCondition:="[Doc ID]=' " & "" & [Doc ID] & "" '"
DoCmd.OpenForm "FrmCustomerExisting", _
WhereCondition:="[Doc ID]=" & Me.[Doc ID]
And many other attempts. Nothing works. Any suggestions would be very much appreciated.
Hi there...I have an issue I'm struggling with...hoping someone can help.
I have a Query that outputs a simple list of records in Datasheet view, and I have an embedded macro that opens an individual record from that datasheet in a Form when you click on it....pretty simple stuff.
The embedded macro passes the value from the field Doc ID to the form's record source field of the same name to ensure that the record clicked is the same one that opens in the form. The form displays the record in edit mode.
The Doc ID field is captured from a table record that is a primary key field, with formatting added to the front (e.g. record 1 displays as WPS001 etc using the format "WPS"000.)
The embedded macro works fine using the where condition: ="[Doc ID]=" & "" & [Doc ID] & ""
The problem...I have tried to replicate the embedded macro in VBA...this is where I get stuck. I have tried multiple variations and suggestions from other sites, and all I can get the form to do is open on a blank record.
For example, I have tried:
DoCmd.OpenForm "FrmCustomerExisting", _
WhereCondition:="[Doc ID]=" & "" & [Doc ID] & ""
DoCmd.OpenForm "FrmCustomerExisting", _
WhereCondition:="[Doc ID]=' " & "" & [Doc ID] & "" '"
DoCmd.OpenForm "FrmCustomerExisting", _
WhereCondition:="[Doc ID]=" & Me.[Doc ID]
And many other attempts. Nothing works. Any suggestions would be very much appreciated.
Last edited: