Insert selected item into Access table

ryprobg

Member
Local time
Today, 18:26
Joined
Sep 3, 2022
Messages
59
hello i m new in this forum proud to be here
 
hello, how are you and what does the title means?
 
hello, how are you and what does the title means?
hello this is my 1st post in this forum i need help:

i have table (t_rec ; column email) and form contain combobox named (nom_mainCBO) and listbox named (emailztxt) contain value depent to the selection of comobox.
the problm is : i want to insert the value of listbox (one item) to the table (t_rec ; column email) without select this item from listbox.
thank you so much ;)
 
Just bind your form to the table?
 
you can also add Code the the Combo's AfterUpdate event:

private sub nom_mainCBO_AfterUpdate()
currentdb.execute "insert into t_rec (email) select '" & me.emailztxt.itemdata(0) & "'"
end sub
 
you can also add Code the the Combo's AfterUpdate event:

private sub nom_mainCBO_AfterUpdate()
currentdb.execute "insert into t_rec (email) select '" & me.emailztxt.itemdata(0) & "'"
end sub
the value is not insert into table (t_rec) until I click on the listbox emailztxt
i try a method to select item but is not working
code :
Private Sub nom_mainCBO_afterUpdate()
Me.emailztxt.Requery
Me.emailztxt.Selected(0) = True
CurrentDb.Execute "insert into t_rec (email) select '" & Me.emailztxt.ItemData(0) & "'"
End Sub
 
i am assuming the first Column of you listbox has the "email" address.
here is a demo.
open t_rec table to verify that it has no record.
open form Form1 and check the code on the combobox's AfterUpdate event.
Open Form1 normally and select anything from the combo.
now open t_rec table again to verify that it has "a@gmail.com" saved.
 

Attachments

the value is not insert into table (t_rec) until I click on the listbox emailztxt
i try a method to select item but is not working
code :
Private Sub nom_mainCBO_afterUpdate()
Me.emailztxt.Requery
Me.emailztxt.Selected(0) = True
CurrentDb.Execute "insert into t_rec (email) select '" & Me.emailztxt.ItemData(0) & "'"
End Sub

for information i want to make automatique insertion to send an Email with boutn SendBtn to get the email item of the list box emailztxt .
code :
Private Sub SendBtn_Click()
Dim olapp As Outlook.Application
Dim olNewMail As Outlook.MailItem
Dim eTo, ccTo, eSubject, ebody As String
eTo =
If IsNull(eTo) Then eTo = ""
ccTo = ""
eSubject = ""
ebody = ""
Set olapp = New Outlook.Application
Set olNewMail = olapp.CreateItem(olMailItem)
olNewMail.To = eTo
olNewMail.CC = ccTo
olNewMail.Subject = eSubject
olNewMail.Body = ebody
olNewMail.Display
End Sub
 
i want to click to sendbtn to Emailing without click to the item of listbox
 
the value is not insert into table (t_rec) until I click on the listbox emailztxt
i try a method to select item but is not working
code :
Private Sub nom_mainCBO_afterUpdate()
Me.emailztxt.Requery
Me.emailztxt.Selected(0) = True
CurrentDb.Execute "insert into t_rec (email) select '" & Me.emailztxt.ItemData(0) & "'"
End Sub

for information i want to make automatique insertion to send an Email with boutn SendBtn to get the email item of the list box emailztxt .
code :
Private Sub SendBtn_Click()
Dim olapp As Outlook.Application
Dim olNewMail As Outlook.MailItem
Dim eTo, ccTo, eSubject, ebody As String
eTo =
If IsNull(eTo) Then eTo = ""
ccTo = ""
eSubject = ""
ebody = ""
Set olapp = New Outlook.Application
Set olNewMail = olapp.CreateItem(olMailItem)
olNewMail.To = eTo
olNewMail.CC = ccTo
olNewMail.Subject = eSubject
olNewMail.Body = ebody
olNewMail.Display
End Sub
the value is not insert into table (t_rec) until I click on the listbox emailztxt
i try a method to select item but is not working
code :
Private Sub nom_mainCBO_afterUpdate()
Me.emailztxt.Requery
Me.emailztxt.Selected(0) = True
CurrentDb.Execute "insert into t_rec (email) select '" & Me.emailztxt.ItemData(0) & "'"
End Sub

for information i want to make automatique insertion to send an Email with boutn SendBtn to get the email item of the list box emailztxt .
code :
Private Sub SendBtn_Click()
Dim olapp As Outlook.Application
Dim olNewMail As Outlook.MailItem
Dim eTo, ccTo, eSubject, ebody As String
eTo =
If IsNull(eTo) Then eTo = ""
ccTo = ""
eSubject = ""
ebody = ""
Set olapp = New Outlook.Application
Set olNewMail = olapp.CreateItem(olMailItem)
olNewMail.To = eTo
olNewMail.CC = ccTo
olNewMail.Subject = eSubject
olNewMail.Body = ebody
olNewMail.Display
End Sub

arnelgp thank you for your help ..at this moment i can't resolve the problem can you help me please :)

 
can you upload your db?
or put in onedrive/google drive and give me the Shared Link?
 
here check and test.
see also the code on each combobox.
 

Attachments

please what is the error in this code :



Private Sub srvCBO_afterupdate()

Me.email_txtBox.Requery
If Len(Me.srvCBO & "") <> 0 Then
Me.email_txtBox = DLookup("Email_Exp", "t_natexp", "service_con = '" & Me.srvCBO) & ""
Me.email_txtBox = ""
End If
End Sub
 
I think an Else is missing. If the length of srvCBO not 0 you fill email and make it empty right away. Put an Else between those two lines.

I don not understand the sense of adding "" to srvCBO.
 
please what is the error in this code :



Private Sub srvCBO_afterupdate()

Me.email_txtBox.Requery
If Len(Me.srvCBO & "") <> 0 Then
Me.email_txtBox = DLookup("Email_Exp", "t_natexp", "service_con = '" & Me.srvCBO) & ""
Me.email_txtBox = ""
End If
End Sub
You do not say what error you are getting? :(
However you set email_txtBox with a DLookup and then immediately clear it?
 
I think an Else is missing. If the length of srvCBO not 0 you fill email and make it empty right away. Put an Else between those two lines.

I don not understand the sense of adding "" to srvCBO.
yes problme in else if statement
thank you
 
in this db a want to get the emails in listbox from selectin combobox multiple choises.
how can i get it tank you for help me.
db in the attachements below
login 🏸 admin
passe 1234
 

Attachments

Users who are viewing this thread

Back
Top Bottom