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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Customizing MsgBoxes

Status
Not open for further replies.

rutkus

Programmer
Aug 28, 2001
41
US
I have a button that adds a record to a field that has the No Duplicates indexed property (but its not a primary key).

So when i click it with a name thats already in that field i get a MsgBox saying:

You can't go to the specified record

My question is, is there any way to customize that?? Can i create my own msgbox over that??

I have no clue whether this is possible, any help would be appreciated.

Thank You,
Omar Qureshy
DSC Networks
 
Set up some error trapping.

private sub button_click()
dim etc etc
on error goto errTrapping

' code goes here

ok:
exit sub

errTrapping:

if err.number = 2105 then
*msgbox err.number
msgbox "Your nessage goes here"
else
msgbox err.description
end if

I am not too sure what the err number will be for this error. Find out by first using the msgbox by the *, then once u have the error number delete the msgbox by the *.
Obviously you won't include the actual *.

Nick
 
Something else i just realized, if i click the exit button and the text box is empty it keeps a blank record, i figure thats because of the required property, but guess what my required property is set to yes.

Mass confusion finds me once again

Omar Qureshy
SUN SPOTS

An eye for an eye only ends up making the whole world blind
--Gandhi
 
Check your that your text box doesn't say 'Allow Zero Length String' = true or yes. Or something on those lines.

Nick
 
nick,

Thanks for the error handling idea

Sadly, i dont find a property that says 'Allow Zero Length String', its probably right under my nose.

hehe, i didnt design this database, im just trying to work with it. if that means anything.

Im also having problems with the delete button, i dont think it ever worked, heres the situation:

Theres a list box with the name of every vendor, im assuming he was trying to set it up so that you highlighted the name of the vendor or vendors, as he had the multiselect function set and it deleted the records from the table. I dont know how possible this is, but i was thinking it might be a little prettier to set it up as a combo box and if the user types in a new company name, an add button appears and they click it and the vendor is added to the combo box(and underlying table), if they pick or type in the name of an existing vendor a delete button appears and they click it and the vendor is gone from the combo box(and underlying table). while i realize this takes away the whole delete multiple vendors at one time function, but they only have like 10 vendors.

How possible is the list idea?? and how possible is the combo box idea??

Just popped in my head:
What happens to those records, in the invoice table, when their respective vendors are deleted?? i know theyre linked and the vendor field in the invoice table is a combo box, would this cause an error when it looks for the vendor?? should i not allow deletion of vendors??

Thanks,
Omar Qureshy
SUN SPOTS
 
The allow zero length is in the table. If you select the particular field, in the bottom half there should be a property. I am at home and don't have access so I can't reallt be more specific unfortunately.
If you have a combo box instead, you can set the 'limit to list' property to 'No' (therefore eliminating the need for an 'Add' button. Then on the 'Not In List' event simply call the requery method for the combo box ie.

private sub combo_linit_To_List( something or other)

combo.requery

end sub

On the delete button you could have:

private sub cmdDelete_Click()
dim db as database
dim sDelete as string

set db = currentdb
sDelete = "Delete * from Vendors where VendorId = " & combo.value
db.execute(sDelete)
combo.requery
end sub

assuming that the combo box is bound to the vendorId field of its underlying table.

Let me know whether I have understand your Q properly. I will be here for a while longer.

Nick


end sub
 
hey nick,

yea, i knew i had seen that allowzerolength option somewhere, thanks, the only problem is i keep getting this error when i set it to no:

Errors where encountered during the save operation. Properties were not updated.

I dont get this anywhere else and i dont know why this error is occuring. Any ideas?? Can i set this property through VB??(i know its a table setting)

I think im gonna stick with his design(the text for add and list for delete), the thing is Access is really bothering me with this whole saving empty or unwanted records thing. It seems if i exit a form with a bound textbox to a table and the textbox is empty or has any letter in it, it automatically saves a new record.(I know allowzerolength will stop the empties but what about the "p" or "a" or any other letter(s)). I have the form open a new record as the form opens itself, to facilitate automatically adding a vendor, but what if the user clicked in there by mistake, hit a key in the process and just clicks the exit button without caring or looking. So i set this code for when you click the exit button:

If [Form_Vendors].Text3.Text = "" Or [Form_Vendors].Text3.Text = " " Then
GoTo Exit_Exit_Click
End
Else

If [Form_Vendors].Text3.Text = [Form_Vendors].List5.Column(0) Then
DoCmd.GoToRecord , , acPrevious
GoTo Exit_Exit_Click
End
End If

Msg = "Do You Wish to Add " + [Form_Vendors].Text3.Text + " To Your List of Vendors?"
Style = vbYesNo

Response = MsgBox(Msg, Style)
If Response = vbYes Then
DoCmd.GoToRecord , , acNewRec
GoTo Exit_Exit_Click
Else
DoCmd.GoToRecord , , acPrevious
GoTo Exit_Exit_Click
End
End If
End If

I know it shouldnt work, theres nothing telling it to not save a record if theres an empty string(this should get fixed with the allowzerolength), then if the text matches the list, it should just go to the previous record and close, but thats not working(it doesnt match the text and list), and finally if its a new record, its supposed to ask if you wanna save it, but it saves it whether you click yes or no. hehe, so basically none of that works, but thats ok, cuz its 9:45 AM and i just finished programming it.

I figure this seems like a problem everyone should have encountered at some point in there Access life. But since ive never had any formal training in access, just reading help files, playing with samples and i just picked up "Microsoft Access 2000: Power Programming" by F. Scott Barker last week, im hoping someone knows how to deal with this.

On to the delete button,

Do you know if its possible to have the list box delete when multiselected or even in general for that matter??

I figure its something like:

DoCmd.FindRecord [Form_Vendors].List5.Column(0)
DoCmd.DoMenuItem acFormBar, acEditMenu, acDelete, , acMenuVer70

But I dont see that working with multiselect.

Well, thanks for your help nick, any ideas here would be much appreciated

Omar Qureshy
HI-Tek



 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top