Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

DAP Find record

Status
Not open for further replies.

VKZIMM

Technical User
Jan 9, 2008
45
US
I copied some code from a previous post. I have a combo box to find the client. It shows names and I have LstBoundfield to Clientnbr and the client number changes to the record it selects, but I want all the fields to be based on the record it selects.
This is the code I am using. ClientLookup is my combo box.
TblRASClients is my table

<SCRIPT language=vbscript event=onchange for=ClientLookup>
<!--
Dim rs
Set rs MSODSC.DefaultRecordset
rs.Find "[TblRASClients] = "" & document.all.item("ClientLookup").value & "",0,1,1

I also need to give a message if they click delete and there is a date in the record. I deleted the delete button and added my own, but I do not know the code for the message and stopping the delete.
Thank you
 
You are trying to search on a table name. You should be searching on the primary key. See:
How to Find a Record from a Drop-down List in a Data Access Page

Create a button using the Command Button on the Toolbox toolbar. It'll start a Wizard. Follow the wizard to create the code. It'll look like:

<SCRIPT language=javascript event=onclick for=Command1>
try { MSODSC.CurrentSection.DataPage.DeleteRecord(); }
catch (e)
{ alert (e.description);}
</SCRIPT>

You can then add code to test for the date and use msgbox to put out a message.
 
That techdoc worked just fine. Thank you, but I do have a few more questions. My combo box only shows one field even though I added number/name, is there a way to change it or does it just work that way. I just added 2 searches, 1 by number and 1 by name for now. I do not know script code, so I have the Delete button added, but I do not know the format for checking the date field and putting out a message box. I did it on a form using a macro, but I do not think you can do that on a DAP.
Thank you again for your quick response.
 
Create a query to concatenate number/name and then use that as your combobox source. eg. [number] & " " & [name]
One way to learn script is by trial and error. It may take a day or month. Look at your first post. You'll see:
document.all.item("ClientLookup").value

So maybe an If statement that looks like:
If document.all.item("DateFieldName").value = null then
try { MSODSC.CurrentSection.DataPage.DeleteRecord(); }
catch (e)
{ alert (e.description);}
Else
msgbox "Can not delete record"
End IF

You may want to check Javascript's If statement for syntax.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top